payload-authjs
Version:
A Payload CMS 3 plugin for Auth.js 5
69 lines (68 loc) • 2.05 kB
TypeScript
import type { NextAuthConfig } from "next-auth";
import type { Adapter } from "next-auth/adapters";
import type { Payload } from "payload";
import { type PayloadAdapterOptions } from "./PayloadAdapter";
type CustomEvent<T extends keyof NonNullable<NextAuthConfig["events"]>> = (message: {
/**
* The Auth.js database adapter
*/
adapter: Adapter;
/**
* The payload instance
*/
payload?: Payload;
} & Parameters<NonNullable<NonNullable<NextAuthConfig["events"]>[T]>>[0]) => void | PromiseLike<void>;
export interface WithPayloadOptions extends PayloadAdapterOptions {
/**
* Update the user after every sign in
*
* @deprecated updateUserOnSignIn is deprecated and will be removed in the future. Use events.signIn instead
*
* @default false
*/
updateUserOnSignIn?: boolean;
/**
* Auth.js events
* All events from authjs will be forwarded and enriched with additional parameters like the adapter and the payload instance
*
* @see https://authjs.dev/reference/nextjs#events
*/
events?: {
/**
* Sign in event
*/
signIn?: CustomEvent<"signIn">;
/**
* Sign out event
*/
signOut?: CustomEvent<"signOut">;
/**
* Create user event
*/
createUser?: CustomEvent<"createUser">;
/**
* Update user event
*/
updateUser?: CustomEvent<"updateUser">;
/**
* Link account event
*/
linkAccount?: CustomEvent<"linkAccount">;
/**
* Session event
*/
session?: CustomEvent<"session">;
};
}
/**
* Wraps the Auth.js configuration
*
* @example
* import { config } from "./auth.config";
*
* export const { handlers, signIn, signOut, auth } = NextAuth(
* withPayload(config, { payloadConfig }),
* );
*/
export declare function withPayload(authjsConfig: NextAuthConfig, { updateUserOnSignIn, events, ...options }: WithPayloadOptions): NextAuthConfig;
export {};