payload-authjs
Version:
A Payload CMS 3 plugin for Auth.js 5
28 lines (27 loc) • 983 B
JavaScript
import crypto from "crypto";
/**
* Create a user and bypass the password check
* This is because payload requires a password to be set when creating a user
*
* @see https://github.com/payloadcms/payload/blob/main/packages/payload/src/collections/operations/create.ts#L254
* @see https://github.com/payloadcms/payload/blob/main/packages/payload/src/auth/strategies/local/generatePasswordSaltHash.ts
*/ export const createUserAndBypassPasswordCheck = async (payload, { collection, data })=>{
// Generate a random password
data.password = crypto.randomBytes(32).toString("hex");
// Create the user
const user = await payload.create({
collection,
data
});
// Remove the salt and hash after the user was created
await payload.update({
collection,
id: user.id,
data: {
salt: null,
hash: null
}
});
return user;
};
//# sourceMappingURL=createUserAndBypassPasswordCheck.js.map