Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Can we use native auth settings? #26

Unanswered
ecan-dearx asked this question in Q&A
Discussion options

Can we use the following settings now local strategies can be used?

 verify: true,
 loginWithUsername: {
 allowEmailLogin: true,
 requireEmail: true,
 },
You must be logged in to vote

Replies: 2 comments 3 replies

Comment options

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"
 }
 ]
}
You must be logged in to vote
0 replies
Comment options

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
 },
],
You must be logged in to vote
3 replies
Comment options

Would credentials provider from authjs still utilize payload's native auth features likeverify, maxLoginAttempts, forgotPassword, etc.?

Comment options

Or should I use payload.login instead?

Comment options

Just use the native Payload authentication payload.login() (see #42)

Please excuse the delayed reply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /