Follow this comprehensive guide to implement Google authentication in your Next.js application. Well cover everything from setting up your Google Cloud Console to implementing the authentication flow.
a. Visit the Google Cloud Console
b. Create a new project or select an existing one
c. Enable the Google OAuth API:
a. Go to "APIs & Services" → "OAuth consent screen"
b. Choose "External" user type
c. Fill in required information:
Configure the following URLs:
Authorized JavaScript origins: http://localhost:3000 https://your-production-domain.com Authorized redirect URIs: http://localhost:3000/api/auth/callback/google https://your-production-domain.com/api/auth/callback/google
Hey there! Let's get Google login working in just 3 simple steps:
1First, head over to the Google Cloud Console and create a new project.
Enable OAuth and grab these two important things:
3️⃣ Add them to your .env file like this:
GOOGLE_CLIENT_ID=your_client_id_here
GOOGLE_CLIENT_SECRET=your_secret_here
🔥 Pro Tip: Make sure to add these URLs to your Google OAuth settings:
Authorized origin: http://localhost:3000
Redirect URI: http://localhost:3000/api/auth/callback/google
Setting up GitHub login is super easy too:
Go to GitHub Developer Settings. GitHub Developer Settings and create a new OAuth app.
Click New OAuth App.
Authorization Callback URL:
http://localhost:3000/api/auth/callback/github
GITHUB_CLIENT_ID=your-github-client-id GITHUB_CLIENT_SECRET=your-github-client-secret
💡 Quick Tip: For your GitHub OAuth settings:
Homepage URL: http://localhost:3000
Authorization callback URL: http://localhost:3000/api/user/auth/callback/github
a. Go to GitHub Settings → Developer Settings → OAuth Apps
b. Click "New OAuth App"
c. Fill in the application details:
After creating the OAuth app:
# .env.local NEXTAUTH_URL=http://localhost:3000 NEXTAUTH_SECRET=your-secret-key # Google credentials GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret # GitHub credentials GITHUB_CLIENT_ID=your-github-client-id GITHUB_CLIENT_SECRET=your-github-client-secret