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

App Router Auth issues in development #4123

Closed
merlindru opened this issue Apr 8, 2023 · 2 comments
Closed

App Router Auth issues in development #4123

merlindru opened this issue Apr 8, 2023 · 2 comments
Labels
Projects

Comments

@merlindru
Copy link

merlindru commented Apr 8, 2023

What is the problem?

From a conversation between @siddhsuresh and I:

In development, it seems like there's a race condition with auth somewhere. I'm constantly redirected back to my login page with useAuthenticatedBlitzContext or getting AuthenticationErrors (with resolver.authorize, for example).

After refreshing multiple times, it works.

siddhsuresh: Ah @merlindru, I remember having and fixing a race condition while creating this hook.
Do you have two useAuthenticatedBlitzContext, one having redirectAuthenticated and one having redirect ?

Merlin: Kind of, I have this:

Login Page --> Home Page (if authenticated)
All other pages (including Home Page) --> Login Page (if logged out)

But

Even if I remove them, I get an AuthenticationError on queries/mutations with resolver.authorize

So it's not the hook that's at fault

Usually it works if I refresh 2-3 times

Paste all your error logs here:

AuthenticationError when using resolver.authorize, redirect loop (sometimes 50+ redirects!) using the setup outlined above

error - node_modules/@blitzjs/rpc/dist/index-server.cjs (79:12) @ $authorize
error - AuthenticationError: You must be logged in to access this
    at Generator.next (<anonymous>)

Paste all relevant code snippets here:

n/a

What are detailed steps to reproduce this?

n/a

Run blitz -v and paste the output here:

Blitz version: 2.0.0-beta.25 (local)
macOS Ventura | darwin-arm64 | Node: v19.8.1


 Package manager: npm

  System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 766.55 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 19.8.1 - /opt/homebrew/bin/node
    Yarn: Not Found
    npm: 9.5.1 - /opt/homebrew/bin/npm
  npmPackages:
    @blitzjs/auth: ^2.0.0-beta.25 => 2.0.0-beta.25 
    @blitzjs/next: ^2.0.0-beta.25 => 2.0.0-beta.25 
    @blitzjs/rpc: ^2.0.0-beta.25 => 2.0.0-beta.25 
    @prisma/client: ^4.12.0 => 4.12.0 
    blitz: ^2.0.0-beta.25 => 2.0.0-beta.25 
    next: ^13.3.0 => 13.3.0 
    prisma: ^4.12.0 => 4.12.0 
    react: ^18.2.0 => 18.2.0 
    react-dom: ^18.2.0 => 18.2.0 
    typescript: ^5.0.2 => 5.0.4 

Please include below any other applicable logs and screenshots that show your problem:

No response

@merlindru merlindru added kind/bug Something isn't working status/triage labels Apr 8, 2023
@flybayer
Copy link
Member

hey @merlindru, could you be so kind as to provide a minimal reproduction of this? We don't have enough info here to reproduce it 🙏

@flybayer flybayer changed the title Auth issues in development App Router Auth issues in development Apr 10, 2023
@siddhsuresh
Copy link
Member

Hey @merlindru please feel to reopen this issue, if you are able to replicate the issue.

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

No branches or pull requests

4 participants