Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Role Based Access Control Page in Guides Section #12462

Open
fbryo21 opened this issue Jan 3, 2025 · 1 comment · May be fixed by #12733
Open

Improve Role Based Access Control Page in Guides Section #12462

fbryo21 opened this issue Jan 3, 2025 · 1 comment · May be fixed by #12733
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@fbryo21
Copy link

fbryo21 commented Jan 3, 2025

What is the improvement or update you wish to see?

The code must be explained more detail, in the Getting a role part.

The code:
return { role: profile.role ?? "user", ... }
(The ... part shows an error said "Expression Expected)

Is there any context that might help us understand?

Give more details explanation about Role Based Access Control, especially using with database (ex: MongoDb)

Does the docs page already exist? Please link to it.

https://authjs.dev/guides/role-based-access-control

@fbryo21 fbryo21 added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Jan 3, 2025
@benhovinga
Copy link
Contributor

Hi @fbryo21,

The ellipsis ( ... ) is what is causing your "Expression Expected" error. I assume this used in the docs to indicate to the developer that more properties can be added to this return statement.

You can remove the ellipsis and it should work as intended.

return { role: profile.role ?? "user", ... }  // Error
return { role: profile.role ?? "user" }  // Works

As for the docs, I think a better solution here would be to put the ellipsis inside a comment with a message to indicate other properties can be added.

export const { handlers, auth } = NextAuth({
  providers: [
    Google({
      profile(profile) {
        return {
          role: profile.role ?? "user",
          // ... other properties
        }
      },
    })
  ],
})

@benhovinga benhovinga linked a pull request Mar 5, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants