-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
App Router: useAuthenticatedBlitzContext
with redirectAuthenticatedTo
results in infinite loop
#4246
Comments
Hey @tordans that's weird, I will take a look today |
Thanks for reporting this issue @tordans! I'm having a similar issue, which is causing problems in production wherever we use |
@chartgerink this issue is specifically for the app router and server components. The solution |
Hey @tordans I finally took a look today, I have opened a PR to use authorise the session that we would expect when we define the roles. Regarding the infinite loop, I feel this is an error in the code you provided. So what happens here is the following:
So I would think if the page is to be protected only to await useAuthenticatedBlitzContext({
role: ["user"],
redirectTo: "/auth/login",
redirectAuthenticatedTo: (ctx) => {
const role = ctx.session.$publicData.role
if (role === "admin") {
return "/admin"
}
return "/user"
}
}) Adding logic to automatically handle the session role in #4257 |
What is the problem?
I am trying to use
useAuthenticatedBlitzContext
to guard an admin area so onlyuser.role==="ADMIN"
is allowed to see the pages.I have a test case in this app: FixMyBerlin/blitz-test@b9c723e
The
redirectTo
works fineHowever, the
redirectAuthenticatedTo
doesnot
validate therole
properly. Instead it results in an infinite loop on the page.I tried working around the issue using the callback for
redirectAuthenticatedTo
but that does not receive any useful input as far as I can see. What is the use case for the callback, actually?Paste all your error logs here:
Paste all relevant code snippets here:
See https://github.com/FixMyBerlin/blitz-test
npx blitz db seed
Test A:
4. Create user on home page, user as ROLE=USER
5. => http://localhost:3000/regions => Redirects to login, which makes sense
Test B:
4. Create user on home page, user as ROLE=ADMIN
5. => http://localhost:3000/regions => Stays on /regions but with infinite loop
What are detailed steps to reproduce this?
Run
blitz -v
and paste the output here:Please include below any other applicable logs and screenshots that show your problem:
No response
The text was updated successfully, but these errors were encountered: