docs
Authentication, Magic Link and Social Login

Authentication, Magic Link, and Social Login

💡

Powered by NextAuth (opens in a new tab), the NextSaaS boilerplate comes with built-in support for popular sign-in services. With just a few updates to environment variables, you can enable Google sign-in, passwordless sign-in (Magic Link), and email/password sign-in in minutes.

Configure Google OAuth

Follow these steps to configure Google OAuth for your NextSaaS application:

1. Create a new project in the Google Cloud Dashboard. Create Project

2. Configure the OAuth consent screen. Here's an example setup for NextSaaS. OAuth Consent Screen

3. Create OAuth client credentials. Credentials Create Credential Create OAuth Client ID

4. Retrieve the OAuth Client ID and Client secret. Client ID and Client secret

5. Ensure that you publish your App in Google Cloud before deploying to production.

Configure Environment Variables

Update your environment variables in the .env file as follows:

.env
# Next Auth
# Replace this with the production host name
NEXTAUTH_URL="http://localhost:3000"
 
# You can generate a new secret on the command line with:
# openssl rand -base64 32
# https://next-auth.js.org/configuration/options#secret
NEXTAUTH_SECRET="{next_auth_secret}"
 
# Next Auth Google Provider
GOOGLE_CLIENT_ID="{oauth_client_id}"
GOOGLE_CLIENT_SECRET="{oauth_client_secret}"