A minimal but complete implementation of 🔐 Google OAuth authentication in a Next.js application using NextAuth.js. This project demonstrates how to set up protected routes and handle authentication flows .
- Node.js 18.x or later
- A Google Cloud Platform account for OAuth credentials
-
Clone the repository:
git clone https://github.com/yourusername/nextjs-google-auth.git cd nextjs-google-auth -
Install dependencies:
npm install
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to “APIs & Services” → “Credentials.”
- Click “Create Credentials” → “OAuth client ID.”
- Choose “Web application” as the application type.
- Under “Authorized redirect URIs,” add:
http://localhost:3000/api/auth/callback/google(for development)- Your production callback URL for deployment
- After creating the credentials, copy the “Client ID” and “Client Secret.”
- Put them in your .env file
- You can also create AUTH_SECRET with a random secret string
-
Start the development server:
npm run dev
-
Visit
http://localhost:3000to see the application.