Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Auth.js · Function

GitHub

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.

How it works

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.

Syntax

GitHub(config?)

Parameters

NameTypeDescription
configOAuthUserConfig<GitHubProfile> & { enterprise: { baseUrl: string } }Optional OAuth provider settings, including explicit client credentials and GitHub-specific configuration.

Returns

OAuthConfig<GitHubProfile>

Key points

  • Auth.js includes GitHub as a built-in OAuth provider.
  • Set the GitHub OAuth client ID and secret using the documented environment-variable names.
  • For Next.js, register the GitHub callback endpoint using the /api/auth/callback/github path.
  • The provider can be used directly when its default OAuth configuration fits the application.
  • Pass explicit client credentials by invoking GitHub with a configuration object.

Example: Configure GitHub authentication

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.

When to use it

Social sign-in

Users authenticate through GitHub in a standard OAuth application.

Convention-based configuration

An application uses GitHub OAuth credentials supplied through environment variables.

Enterprise GitHub

An enterprise GitHub deployment needs a custom API endpoint.

Interview questions

QHow do you add GitHub login to an Auth.js application?

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.

QWhat callback URL must be configured for GitHub OAuth?

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.

QHow are GitHub client credentials configured?

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.

  • GitHubProfile
  • OAuthUserConfig
  • OAuthConfig
  • providers
  • NextAuth
  • AUTH_GITHUB_ID
  • AUTH_GITHUB_SECRET

Source: providers/github - Auth.js. Checked 2026-10-15.