Authentication

ShipAny currently supports three login methods: Google Login / Google One-Tap Login / Github Login.

Other login methods will be integrated gradually. You can also refer to the next-auth documentation to implement them yourself.

Generate Auth Secret

Run in terminal:

Terminal
openssl rand -base64 32

This generates a 32-byte random string to use as Auth Secret

Modify the AUTH_SECRET value in your environment variables:

.env.development
AUTH_SECRET = "xxx"

Google Login

  1. Sign in to Google Cloud Console

Create a new project, go to the Credentials management page of the new project, and create an OAuth Client ID

google-console

  1. Configure the necessary callback information according to your project’s port and production domain
callbackUrl
https://localhost:3000/api/auth/callback/google

google-clientid

After creating the OAuth Client ID, you’ll receive a Client ID and Client Secret

  1. Modify AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET in your configuration file

Enable Google login:

.env.development
AUTH_GOOGLE_ID = "4680xx-xxx.apps.googleusercontent.com"
AUTH_GOOGLE_SECRET = "GOxxx"

NEXT_PUBLIC_AUTH_GOOGLE_ENABLED = "true"

Google One-Tap Login

First, follow the Google login steps to obtain AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET

Modify NEXT_PUBLIC_AUTH_GOOGLE_ONE_TAP_ENABLED and NEXT_PUBLIC_AUTH_GOOGLE_ID in your configuration file

Enable Google One-Tap login:

.env.development
NEXT_PUBLIC_AUTH_GOOGLE_ONE_TAP_ENABLED = "true"
NEXT_PUBLIC_AUTH_GOOGLE_ID = "4680xx-xxx.apps.googleusercontent.com"

The NEXT_PUBLIC_AUTH_GOOGLE_ID used for Google One-Tap login should be the same as the AUTH_GOOGLE_ID configured for Google login.

Github Login

  1. Go to Github Developer Settings

Create a new OAuth app

  1. Fill in the OAuth app configuration information
callbackUrl
https://localhost:3000/api/auth/callback/github

github-callback

For development and production environments, you need to create two different OAuth apps with different callback URLs.

  1. Enter the OAuth app, copy the Client ID and Client Secret

  2. Modify AUTH_GITHUB_ID and AUTH_GITHUB_SECRET in your configuration file

Enable Github login:

.env.development
AUTH_GITHUB_ID = "xxx"
AUTH_GITHUB_SECRET = "xxx"
NEXT_PUBLIC_AUTH_GITHUB_ENABLED = "true"

Login Preview

  1. Click the login button to open the login popup

login-preview

  1. When users enter the homepage, they’ll be prompted with one-tap login

google-onetap

References