payload
payload copied to clipboard
"disableLocalStrategy: true" still asking for email or nickname
Environment Info
"next": "15.0.0-canary.104",
"payload": "beta",
"nodejs": v18.20.4
Describe the Bug
I want to create a custom auth for trainees that can login with their firstname, lastname and trainee_id. There is no need for password, email or nicknames. I've find out that disableLocalStrategy set to true is ignored and still requires email/nickname and password. If i'm doing something wrong, please tell me how to fix it?
Reproduction Steps
import type {CollectionConfig} from 'payload'
export default {
slug: 'trainees',
labels: {
singular: 'Azubi',
plural: 'Azubis',
},
auth: {
disableLocalStrategy: true,
strategies: [
{
identityField: 'trainee_id',
name: 'custom-strategy',
async authenticate({headers, payload}) {
const {docs} = await payload.find({
collection: 'trainees',
where: {
name_first: {equals: headers.get('name_first')},
name_last: {equals: headers.get('name_last')},
trainee_id: {equals: headers.get('trainee_id')},
},
})
return {user: docs[0]}
},
},
],
},
fields: [
{
name: 'name_first',
label: 'Vorname',
type: 'text',
required: true,
},
{
name: 'name_last',
label: 'Nachname',
type: 'text',
required: true,
},
{
name: 'trainee_id',
label: 'Matrikelnummer',
type: 'text',
required: true,
},
],
} as const satisfies CollectionConfig
is called by
const result = await payload.login({
collection: 'trainees',
data: {
name_first: 'Hassan',
name_last: 'Altay',
trainee_id: '43523452345',
},
})
console.log(result)
causes
dock-payload | ⨯ node_modules/payload/dist/auth/operations/login.js (56:1) @ loginOperation
dock-payload | ⨯ ValidationError: The following field is invalid: email
dock-payload | at async $$ACTION_0 (./src/app/logic/actions.ts:52:20)
dock-payload | digest: "1954918542"
dock-payload | Cause: {
dock-payload | collection: 'trainees',
dock-payload | errors: [ { field: 'email', message: 'This field is required.' } ]
dock-payload | }
dock-payload | 54 | // cannot login with username, did not provide email
dock-payload | 55 | if (!canLoginWithUsername && !sanitizedEmail) {
dock-payload | > 56 | throw new ValidationError({
dock-payload | | ^
dock-payload | 57 | collection: collectionConfig.slug,
dock-payload | 58 | errors: [
dock-payload | 59 | {