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

Page authenticate role #3902

Merged
merged 24 commits into from
Nov 9, 2022
Merged

Page authenticate role #3902

merged 24 commits into from
Nov 9, 2022

Conversation

siddhsuresh
Copy link
Member

@siddhsuresh siddhsuresh commented Oct 15, 2022

Closes: #2399

What are the changes and their implications?

  • add option role to the authenicate property to authorize users depending on their role

Values that can be passed to role property is string or an array of strings

Used the following convention [mentioned in the issue]

// user must be logged in
Page.authenticate = true 
// user must be logged in and redirects otherwise
Page.authenticate = { redirectTo: "/login" }
// user must be logged in and with role "ADMIN" or "USER"
Page.authenticate = { role: ["ADMIN", "USER"] }
// user must be logged in with role "ADMIN" and redirects otherwise
Page.authenticate = { role: "ADMIN", redirectTo: "/login" }

Feature Checklist

  • Changeset added (run pnpm changeset in the root directory)
  • fixed test in packages\blitz-auth\src\client\auth-client.test.ts to show role as public
  • Documentation added/updated (submit PR to blitzjs.com repo main branch)

@changeset-bot
Copy link

changeset-bot bot commented Oct 15, 2022

🦋 Changeset detected

Latest commit: 7da9bb0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@blitzjs/auth Patch
@blitzjs/next Patch
@blitzjs/rpc Patch
@blitzjs/codemod Patch
@blitzjs/config Patch
@blitzjs/generator Patch
blitz Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@itsdillon
Copy link
Member

@siddhsuresh Were you able to update the docs with this? Great job as always!

@siddhsuresh
Copy link
Member Author

@siddhsuresh Were you able to update the docs with this? Great job as always!

@dillonraphael I linked the updated docs PR

apps/web/pages/page-with-redirect.tsx Outdated Show resolved Hide resolved
apps/web/app/mutations/createUser.ts Outdated Show resolved Hide resolved
@itsdillon
Copy link
Member

Sorry @siddhsuresh, can we just get the conflicts resolved? Going to get this merged and released.

@siddhsuresh
Copy link
Member Author

Sorry @siddhsuresh, can we just get the conflicts resolved? Going to get this merged and released.

@dillonraphael I resolved the merge conflict

@itsdillon itsdillon merged commit 97469a1 into main Nov 9, 2022
@itsdillon itsdillon deleted the page-authenticate-role branch November 9, 2022 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Authenticate page based on user role
3 participants