Add Google sign-in to an Auth.js application
User authentication
Auth.js · Function
Google is a built-in Auth.js OAuth provider. Add it to the framework configuration, provide Google OAuth credentials, and register the provider-specific callback URL.
The built-in Google provider supplies the OAuth/OIDC configuration used by Auth.js. Add it to the framework adapter's providers list, configure the matching credentials through environment variables, and register the generated callback URL in Google Cloud; customize authorization parameters when offline refresh tokens are needed.
Google(options?)| Name | Type | Description |
|---|---|---|
options | GoogleConfig | Google provider options, including optional OAuth client credentials and authorization settings. |
A configured Auth.js Google provider object for use in the providers array.
AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET.email_verified boolean that can inform account or email handling.import NextAuth from "next-auth"
import Google from "next-auth/providers/google"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [Google],
})Register the built-in Google provider in a Next.js Auth.js configuration. Define AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET in the environment before starting the application.
User authentication
Credential management
Token access
Import the provider from the framework-specific providers package and include it in the Auth.js providers array. With automatic environment-variable discovery, the expected names are AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET.
Follow-up: How would you configure explicit credentials? Pass clientId and clientSecret to Google({...}) instead of using the shorthand provider value.
For Next.js, the callback is /api/auth/callback/google, so a production deployment uses https://<your-domain>/api/auth/callback/google. That exact URI must be registered as an authorized redirect URI in Google Cloud.
Follow-up: What changes for Express? The default callback is /auth/callback/google, unless the Auth.js handler is mounted at a different path.
Google follows an OpenID Connect-based default configuration and returns an email_verified boolean in the OAuth profile. If the application needs a refresh token, configure authorization parameters such as access_type: "offline", response_type: "code", and commonly prompt: "consent".
Follow-up: Why might offline access still fail to produce a refresh token? Google generally supplies one only on the first user authorization, so the consent state and prior grants matter.
OAuth ProvidersCustomizing a built-in OAuth providerEnvironment VariablesAuthConfig.providers