⚡ BolkAuth

createBolkAuth(config) creates the auth engine used by the Next.js route handler, middleware, and server helpers.

import { createBolkAuth } from "@bolkauth/core";
 
export const auth = createBolkAuth({
  adapter,
  secret: process.env.BOLKAUTH_SECRET!,
});

Required Options

OptionTypeDescription
adapterBolkAuthAdapterDatabase adapter for users, sessions, OAuth accounts, verification tokens, and metadata.
secretstringSecret used to sign session JWTs. Use at least 32 random characters.

Session Options

session: {
  maxAge: 60 * 60 * 24 * 30,
  updateAge: 60 * 60 * 24,
  strategy: "jwt",
  cookieName: "bolkauth.session",
}
OptionTypeDescription
maxAgenumberSession lifetime in seconds. Defaults to 30 days.
updateAgenumberReserved for session refresh behavior.
strategy"jwt" | "database"Session strategy field for configuration compatibility. Current middleware validates the JWT cookie.
cookieNamestringCookie name. Defaults to bolkauth.session.

Email and Password

emailAndPassword: {
  enabled: true,
  minPasswordLength: 8,
  requireEmailVerification: false,
}
OptionTypeDescription
enabledbooleanEnables email/password sign-up and sign-in configuration.
minPasswordLengthnumberMinimum password length. Defaults to 8.
requireEmailVerificationbooleanReserve this for flows that require verified email before access.

Email Delivery

email: {
  sendMagicLink: async ({ identifier, url, token }) => {},
  sendOTP: async ({ email, code, expiresAt }) => {},
  verifyRedirectUrl: "/dashboard",
}
OptionDescription
sendVerificationRequestSend a verification email.
sendMagicLinkSend the magic-link URL generated by BolkAuth.
sendOTPSend the numeric OTP code generated by BolkAuth.
verifyRedirectUrlRedirect target after a magic-link verification succeeds.

OAuth

socialProviders: {
  github: {
    clientId: process.env.GITHUB_CLIENT_ID!,
    clientSecret: process.env.GITHUB_CLIENT_SECRET!,
    scopes: ["user:email", "read:user"],
  },
},
social: {
  redirectUrl: "/dashboard",
}

socialProviders is keyed by provider name. Built-in OAuth helpers currently support common provider names such as github and google.

OTP

otp: {
  expiresIn: 600,
  codeLength: 6,
  maxAttempts: 5,
  onRateLimitExceeded: async (email) => {},
}
OptionTypeDefault
expiresInnumber600 seconds
codeLength4 | 6 | 86
maxAttemptsnumber5
onRateLimitExceeded(email: string) => Promise<void>Not set

Onboarding

onboarding: {
  enabled: true,
  requiredForAccess: true,
  redirectUrl: "/onboarding",
  steps: ["profile", "team"],
}

Onboarding endpoints store progress through the adapter metadata methods. Use middleware to redirect users that need to complete setup.

On this page