Social sign-in
Users authenticate through GitHub in a standard OAuth application.
Auth.js · Function
The GitHub provider adds GitHub OAuth sign-in to Auth.js. Use it directly in the providers list or call it with configuration to override defaults.
Add the GitHub provider to the Auth.js configuration, then supply its credentials through the conventional environment variables. Auth.js uses the provider's OAuth flow and exposes framework helpers such as handlers, auth, signIn, and signOut from the configured instance.
GitHub(config?)| Name | Type | Description |
|---|---|---|
config | OAuthUserConfig<GitHubProfile> & { enterprise: { baseUrl: string } } | Optional OAuth provider settings, including explicit client credentials and GitHub-specific configuration. |
OAuthConfig<GitHubProfile>
import NextAuth from "next-auth"
import GitHub from "next-auth/providers/github"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [GitHub],
})Register GitHub as a provider in the Auth.js configuration. Auth.js reads AUTH_GITHUB_ID and AUTH_GITHUB_SECRET automatically, while the exported helpers support authentication actions.
Users authenticate through GitHub in a standard OAuth application.
An application uses GitHub OAuth credentials supplied through environment variables.
An enterprise GitHub deployment needs a custom API endpoint.
Import the framework-specific GitHub provider and include it in the providers array passed to NextAuth. With the conventional environment variables configured, the provider can be supplied directly as GitHub.
Follow-up: How are credentials inferred? Auth.js maps AUTH_GITHUB_ID and AUTH_GITHUB_SECRET to the provider's clientId and clientSecret options.
The callback URL is framework-dependent, but the Next.js form is https://example.com/api/auth/callback/github. That URL must be registered in the GitHub OAuth application settings.
Follow-up: What is needed for separate environments? Register a separate GitHub OAuth application when another environment requires a different callback URL.
Use AUTH_GITHUB_ID and AUTH_GITHUB_SECRET in the environment. Auth.js conventionally infers these values for the GitHub provider, so explicit provider arguments are usually unnecessary.
Follow-up: When would explicit options be appropriate? Call GitHub with an options object when overriding defaults or supplying non-inferred configuration.
GitHubProfileOAuthUserConfigOAuthConfigprovidersNextAuthAUTH_GITHUB_IDAUTH_GITHUB_SECRET