To enable Google Login for the Krausz Webshop, follow these steps to create your credentials in the Google Cloud Console.
- Go to the Google Cloud Console.
- Create a new project (e.g., "Krausz Webshop").
- Go to APIs & Services > OAuth consent screen.
- Select External and Click Create.
- Fill in the required App information:
- App name:
Krausz Webshop - User support email: (Your email)
- Developer contact info: (Your email)
- App name:
- Click Save and Continue through the Scopes and Test Users screens.
- Go to APIs & Services > Credentials.
- Click + Create Credentials > OAuth client ID.
- Select Web application as the Application type.
- Name:
Krausz Webshop Web Client. - Authorized JavaScript origins:
http://localhost:3000https://your-production-domain.comhttps://your-ngrok-subdomain.ngrok-free.app(only if testing via tunnel)
- Authorized redirect URIs:
http://localhost:3000/api/auth/callback/googlehttps://your-production-domain.com/api/auth/callback/googlehttps://your-ngrok-subdomain.ngrok-free.app/api/auth/callback/google(only if testing via tunnel)
- Click Create.
- Copy your Client ID and Client Secret.
Use one host per login flow from start to callback:
localhostflow: start sign-in onhttp://localhost:3000and return tohttp://localhost:3000.ngrokflow: start sign-in on the ngrok URL and return to the same ngrok URL.- production flow: start and return on the production domain.
Do not start on one host and complete callback on another host, because PKCE/state cookies are host-bound and Auth.js will fail with InvalidCheck.
Add the following variables to your project's .env file:
AUTH_GOOGLE_ID=your_client_id_here
AUTH_GOOGLE_SECRET=your_client_secret_here
AUTH_SECRET=a_random_secret_string (run `npx auth secret` to generate one)
AUTH_URL=http://localhost:3000
NEXTAUTH_URL=http://localhost:3000
AUTH_TRUST_HOST=trueFor reverse-proxy deployments, set:
AUTH_URL=https://your-production-domain.com
NEXTAUTH_URL=https://your-production-domain.com
AUTH_TRUST_HOST=trueBy default, new users are created with the USER role. To access the admin dashboard, you can manually update your user record in MongoDB:
// MongoDB command
db.users.updateOne({ email: "your-email@gmail.com" }, { $set: { role: "ADMIN" } })