UNPKG

payload-authjs

Version:
36 lines (35 loc) 1.39 kB
import type { NextAuthConfig } from "next-auth"; import type { Adapter } from "next-auth/adapters"; import type { Payload } from "payload"; import type { AuthCollectionSlug } from "../payload/plugin"; /** * An enriched version of the NextAuthConfig that includes the payload instance and database adapter in event callbacks */ export type EnrichedAuthConfig<TConfig extends NextAuthConfig = NextAuthConfig> = { events?: EnrichedEvents<TConfig>; } & Omit<TConfig, "events">; type EnrichedEvents<TConfig extends NextAuthConfig> = { [EventName in keyof NonNullable<NextAuthConfig["events"]>]?: (message: { /** * The Auth.js database adapter */ adapter?: Adapter; /** * The payload instance */ payload?: Payload; } & Parameters<NonNullable<NonNullable<TConfig["events"]>[EventName]>>[0]) => void | PromiseLike<void>; }; /** * Setup Auth.js configuration * * - Register the Payload adapter for Auth.js * - Set default session strategy to "jwt" if not already set * - Enrich the Auth.js configuration by wrapping event callbacks to include the payload instance and database adapter */ export declare const withPayloadAuthjs: ({ payload, config, collectionSlug, }: { payload: Payload; config: EnrichedAuthConfig<NextAuthConfig>; collectionSlug: AuthCollectionSlug; }) => NextAuthConfig; export {};