Skip to content

chore(docs): Fix syntax error in RBAC guide #12733

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

Merged
merged 5 commits into from
Jun 22, 2025

Conversation

benhovinga
Copy link
Contributor

@benhovinga benhovinga commented Mar 5, 2025

☕️ Reasoning

Moved the Ellipsis ( ... ) onto a separate line as a comment. The Ellipsis was throwing "Expression Expected" error. I assume this was used to indicate to the developer that more properties can be added here. Moving it inside of a comment performs the same function without throwing any errors.

Before

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

After

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

This fix has been applied to all frameworks.

🧢 Checklist

  • Documentation
  • Tests - N/A
  • Ready to be merged

🎫 Affected issues

Fixes: #12462

📌 Resources

@benhovinga benhovinga requested a review from ndom91 as a code owner March 5, 2025 14:35
Copy link

vercel bot commented Mar 5, 2025

@benhovinga is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Mar 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 22, 2025 11:20am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Jun 22, 2025 11:20am

@tgeorge73
Copy link

I believe the proposed documentation update is incorrect. The ... is not an ellipse, but the spread operator. (The error occurs in typescript because the spread operator is missing the object to spread, in this case profile).

So removing the ", ..." as proposed causes the user to be created in the database with ONLY the properties in the function. changing "..." to "...profile" causes the properties from the profile to be merged with the values set manually in the function.

One other note, specific to the spread operator, is the order of statements with respect to the spread operator. When the spread operator is last, the properties of the profile (object being spread) from the IdP will override and matching property statement manually set -- this seems safest as a pattern such that the IdP identity information is most accurate. If the spread operator is first, then any manually set properties will override matching properties returned from the IdP profile. (This would only be appropriate if there was a valid reason to change an IdP provided value -- which arguably should not be done.) While not applicable to the role property because it does not exist in the profile, this is an important note in my opinion as it can be a source of confusion to newer devs (maybe link out to spread operator documentation here?)

@benhovinga
Copy link
Contributor Author

benhovinga commented May 22, 2025

@tgeorge73

The ... is not an ellipse, but the spread operator. (The error occurs in typescript because the spread operator is missing the object to spread, in this case profile).

Ah, this makes more sense. Usually when I see ... on it's own I assume this is a placeholder. It is clear now that profile was missing after it to make it a spread operator.

So this should be the correct version

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

When I get on my dev machine I will update the PR.

@benhovinga benhovinga marked this pull request as draft May 22, 2025 12:10
Copy link
Member

@ndom91 ndom91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

EDIT: Ah just read the comments. Not sure if it was meant as a spread operator where the author just forgot the profile part. But that should ideally be there, so let's go that route.

If you update it I can get this merged. Sorry for the delay!

@benhovinga benhovinga marked this pull request as ready for review June 3, 2025 15:19
@benhovinga benhovinga requested a review from ndom91 June 3, 2025 15:19
@benhovinga
Copy link
Contributor Author

Corrected the spread operator to ...profile

@ThangHuuVu ThangHuuVu merged commit 63d90a0 into nextauthjs:main Jun 22, 2025
11 of 13 checks passed
@benhovinga benhovinga deleted the docs-guide-rbac branch June 23, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Role Based Access Control Page in Guides Section
4 participants