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

Auth.js · Const

GitLab

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.

How it works

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.

Syntax

GitLab(options): OAuthConfig<P>

Parameters

NameTypeDescription
optionsOAuthUserConfig<P> & { baseUrl: string | URL; }OAuth user configuration and a GitLab base URL, supplied as either a string or URL.

Returns

OAuthConfig<P>

Key points

  • Auth.js supplies GitLab as a built-in integration rather than requiring a custom provider definition.
  • The provider follows OAuth 2 semantics unless its configuration is customized.
  • Standard setups can use the provider's built-in defaults and override them only when the application needs different behavior.
  • The documented API callback endpoint ends with /api/auth/callback/gitlab.

Common mistakes

  • Add the read_user scope when registration must retain the user's email address.

Example: Configure GitLab authentication

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.

When to use it

GitLab sign-in

Users authenticate through GitLab in an Auth.js application.

Use the built-in OAuth integration

An application needs GitLab OAuth behavior without implementing provider endpoints itself.

Customize provider configuration

A deployment needs a non-default GitLab endpoint or provider behavior.

Interview questions

QHow do you configure GitLab in Auth.js?

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.

QWhat callback URL should a GitLab OAuth application use?

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.

QWhat are the GitLab provider's parameter and return types?

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.

  • OAuthConfig
  • GitLabProfile
  • OAuthUserConfig
  • customizing a built-in OAuth provider

Source: Gitlab - Auth.js. Checked 2026-10-15.