Function: configureAuthRuntime()
function configureAuthRuntime(config, options): void
Initializes Auth.js in local mode by creating a reusable handler that Robo's
server utilities can call. Invoke this during plugin startup (e.g., inside
the _start event) before any auth routes are accessed.
⚠️ Security:
- Call from server-only code;
configoften contains provider secrets. - Do not log the
configobject or runtime options in production.
Performance:
- The Auth handler is created once and reused for every request (no per-request setup).
- ensureCredentialsDbCompatibility mutates
configto add database support; the patch is cached on the object.
Edge cases:
- Calling multiple times overwrites the previous configuration; call once.
- Must run before any auth route executes, otherwise helpers throw "unconfigured" errors.
configis mutated. Clone it first if you need the original object elsewhere.options.sessionStrategymust match your Auth.js adapter/session configuration (JWT vs database).options.basePathmust match the Auth.js configbasePathor Auth routes will 404.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | AuthConfig | Complete Auth.js configuration (providers, adapter, callbacks, etc.). |
options | ConfigureAuthRuntimeOptions | Runtime values (ConfigureAuthRuntimeOptions). |
Returns
void
Nothing; sets module-scoped state used by getServerSession and getToken.
Examples
export default async function start() {
const config: AuthConfig = { providers: [...], adapter: createFlashcoreAdapter({ secret: process.env.AUTH_SECRET! }) }
configureAuthRuntime(config, {
basePath: '/api/auth',
baseUrl: process.env.AUTH_URL!,
cookieName: 'authjs.session-token',
secret: process.env.AUTH_SECRET!,
sessionStrategy: 'database'
})
}
configureAuthRuntime(authConfig, {
basePath: '/internal/auth',
baseUrl: 'https://example.com',
cookieName: '__Secure-authjs.session-token',
secret: process.env.AUTH_SECRET!,
sessionStrategy: 'jwt'
})
See
- ensureCredentialsDbCompatibility
- Auth from
@auth/core - getServerSession
- getToken
- configureAuthProxyRuntime for proxy mode