payload-authjs
Version:
A Payload CMS 3 plugin for Auth.js 5
31 lines (30 loc) • 1.2 kB
JavaScript
/**
* Get the Auth.js instance from the payload instance
*/ export const getAuthjsInstance = (payload, collectionSlug = "users")=>{
const authjsInstances = payload.__authjs_instances__?.[collectionSlug];
if (!authjsInstances || typeof authjsInstances !== "object") {
payload.logger.error(`Auth.js instance for collection '${collectionSlug}' not found. Ensure that you have added the authjsPlugin to your payload config.`);
throw new Error(`Auth.js is not initialized for collection '${collectionSlug}'`);
}
return authjsInstances;
};
/**
* Set the Auth.js instance in the payload instance
*/ export const setAuthjsInstance = (payload, collectionSlug, authjs)=>{
const _payload = payload;
if (!_payload.__authjs_instances__) {
Object.defineProperty(payload, "__authjs_instances__", {
value: {},
writable: false,
configurable: false,
enumerable: false
});
}
Object.defineProperty(_payload.__authjs_instances__, collectionSlug, {
value: authjs,
writable: false,
configurable: false,
enumerable: true
});
};
//# sourceMappingURL=getAuthjsInstance.js.map