payload-authjs
Version:
A Payload CMS 3 plugin for Auth.js 5
38 lines (37 loc) • 1.43 kB
JavaScript
import { PayloadAdapter } from "./PayloadAdapter";
/**
* 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 const withPayloadAuthjs = ({ payload, config, collectionSlug })=>{
const adapter = PayloadAdapter({
payload,
userCollectionSlug: collectionSlug
});
return {
...config,
session: {
...config.session,
// Set default session strategy to "jwt"
strategy: config.session?.strategy || "jwt"
},
// Register the Payload adapter for authjs
adapter,
...config.events && {
// Enrich event callbacks to include the payload instance and adapter
events: Object.entries(config.events).reduce((events, [eventName, callback])=>{
events[eventName] = (message)=>callback({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...message,
// Add the payload instance and the adapter
payload,
adapter
});
return events;
}, {})
}
};
};
//# sourceMappingURL=withPayloadAuthjs.js.map