GitLab sign-in
Users authenticate through GitLab in an Auth.js application.
Auth.js · Const
Auth.js provides a built-in GitLab OAuth 2 provider. Configure it with GitLab client credentials and register it in the Auth.js providers list.
The GitLab provider is a built-in OAuth integration. Call it with provider configuration, including the client ID and secret, then place the resulting provider in Auth.js's providers list; use the documented callback path for the OAuth redirect.
GitLab(options): OAuthConfig<P>| Name | Type | Description |
|---|---|---|
options | OAuthUserConfig<P> & { baseUrl: string | URL; } | OAuth user configuration and a GitLab base URL, supplied as either a string or URL. |
OAuthConfig<P>
/api/auth/callback/gitlab.read_user scope when registration must retain the user's email address.import { Auth } from "@auth/core"
import GitLab from "@auth/core/providers/gitlab"
const request = new Request(origin)
const response = await Auth(request, {
providers: [
GitLab({
clientId: process.env.GITLAB_CLIENT_ID,
clientSecret: process.env.GITLAB_CLIENT_SECRET,
}),
],
})Registers GitLab as an OAuth provider with Auth.js and supplies the client credentials required by the integration.
Users authenticate through GitLab in an Auth.js application.
An application needs GitLab OAuth behavior without implementing provider endpoints itself.
A deployment needs a non-default GitLab endpoint or provider behavior.
GitLab is configured as a built-in provider by importing GitLab from @auth/core/providers/gitlab and adding GitLab({ clientId, clientSecret }) to the providers array. Auth.js treats the integration as OAuth 2 by default.
Follow-up: How would you preserve a user's email during sign-up? Add the read_user option to the OAuth scope.
The OAuth redirect endpoint is https://example.com/api/auth/callback/gitlab. The provider's identifier determines the final gitlab segment of that callback URL.
Follow-up: What must change for a deployed application? Replace example.com with the application's public origin while retaining the callback path.
The provider function accepts OAuth user configuration together with a baseUrl string or URL. It returns an OAuthConfig parameterized by the GitLab profile type.
Follow-up: Why might baseUrl be supplied? It allows the provider configuration to target the intended GitLab base URL rather than relying on the default.
OAuthConfigGitLabProfileOAuthUserConfigcustomizing a built-in OAuth provider