-
Notifications
You must be signed in to change notification settings - Fork 9
Can we use native auth settings? #26
-
Can we use the following settings now local strategies can be used?
verify: true,
loginWithUsername: {
allowEmailLogin: true,
requireEmail: true,
},
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 3 replies
-
Looks like this setting causes problems with this plugin. This requires username
to be populated, which is not the case when you login with oauth...
[auth][details]: {
"collection": "users",
"errors": [
{
"label": "Username",
"message": "This field is required.",
"path": "username"
}
]
}
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes, you can.
But the problem is that the user requires a username
, but your provider does not provide a username by default.
There are 3 possible solutions for this:
1. Make username optional:
auth: { loginWithUsername: { allowEmailLogin: true, requireEmail: true, requireUsername: false, // <-- Make it optional }, },
2. Extend your Auth.js profile from your provider:
providers: [ github({ async profile(profile, tokens) { return { // Default fields from github provider ...(await github({}).profile!(profile, tokens)), // Custom fields username: profile.login, // <-- Add username field }; }, }), ],
More information about extending your session can be found in the Auth.js documentation.
3. Set a default value for the username field:
fields: [ { name: "username", type: "text", defaultValue: () => crypto.randomUUID(), // <-- Generate a random uuid or something else }, ],
Beta Was this translation helpful? Give feedback.
All reactions
-
Would credentials
provider from authjs still utilize payload's native auth features likeverify
, maxLoginAttempts
, forgotPassword
, etc.?
Beta Was this translation helpful? Give feedback.
All reactions
-
Or should I use payload.login
instead?
Beta Was this translation helpful? Give feedback.
All reactions
-
Just use the native Payload authentication payload.login()
(see #42)
Please excuse the delayed reply
Beta Was this translation helpful? Give feedback.