sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.31k stars 164 forks source link

Provider refresh causes Infinite redirect at sign-in page #792

Closed hiroki-otaka closed 4 months ago

hiroki-otaka commented 4 months ago

Environment

Reproduction

  1. Clone the repo
  2. cd nuxt-auth/playground-refresh
  3. Edit pages/index.vue to comment definePageMeta({ auth: false }) out
  4. Run dev server and open local pages

Describe the bug

Error "500 Infinite redirect in navigation guard" is shown.

The same procedure in playground-local has no problem. The documentation states that the local provider and the refresh provider is the same except refreshing tokens. The refresh provider should treat the login path as special as the local provider does.

Additional context

No response

Logs

No response

github-actions[bot] commented 4 months ago

Hello 👋

Please provide a reproduction for this issue 🙏

How can I create a reproduction? Please use one of the following links to reproduce your issue. - https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz - https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox Please ensure that the reproduction is as **minimal** as possible. This will allow us to isolate the issue as best as possible. Here are some more amazing posts about the importance of reproductions: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example)
hiroki-otaka commented 4 months ago

https://stackblitz.com/edit/github-4rxvta?file=pages%2Findex.vue,app.vue,nuxt.config.ts

Key points are:

The local provider seems to prevent this error. https://github.com/sidebase/nuxt-auth/blob/8e6519f90f00c7b4478ed34088d69e5bcb0ba5dc/src/runtime/middleware/auth.ts#L70-L75

zoey-kaiser commented 4 months ago

Hi @hiroki-otaka 👋

This makes sense. The expectation for the local provider was added wayyyy back in 2023 #543, before the refresh provider was added. I assume it slipped through when we created it, however the fix should be very easy. Would you like to push a PR and include the refresh provider in the same check?

hiroki-otaka commented 4 months ago

Thank you for explaining backgrounds. And sure, I'll make a PR.