nuxt-modules / supabase

Supabase module for Nuxt.
https://supabase.nuxtjs.org
MIT License
733 stars 129 forks source link

Constant redirection to Login #239

Closed R0N1n-dev closed 1 year ago

R0N1n-dev commented 1 year ago

Version

@nuxtjs/supabase: 1.0.2 nuxt: 3.6.5

Reproduction Link

https://stackblitz.com/github/R0N1n-dev/nux-supauth

Steps to reproduce

Installed supabase module Created Login, register pages and added logic from supabase client.

What is Expected?

Dev server starting successfully Being able to navigate between my non authenticated pages.

What is actually happening?

Problem 1: As soon as including the module in the modules section in nuxt.config.ts and running the dev server, it instantly redirects to a login route, regardless of if said page exists or not. On removing module from modules section, dev server runs fine.

Problem 2: In addition, I cannot navigate to any other page at all.
It just sticks to login route and page.

Aietes commented 1 year ago

By default the module checks for authentication, and if no authorized user is found, redirects to a login page. In your example you added a middleware, but the module already adds one for you, so you should not add another one. Simply remove your middleware, and see if it works.

You can disable the redirect for the entire app and handle checks and redirects yourself. But be aware that there are some details you have to take care of as discussed in #227, so it's easier to use the module with redirect: true.

export default defineNuxtConfig({
  // ...
  supabase: {
    redirect: false
  }
}

You can also exclude routes from the auth check in your nuxt.config, where ['/foo', '/bar/*'] will exclude the foo page and all pages in your bar folder.:

export default defineNuxtConfig({
  // ...
  supabase: {
    redirectOptions: {
      exclude: ['/foo', '/bar/*'],
    }
  }
}

There currently is a bug in the auth middleware, that falsely redirects to the login page on non-SSR routes, but that shouldn't apply to your case. #237 will fix that bug once it's merged.

R0N1n-dev commented 1 year ago

Removing my middleware and leaving redirect on true has me stuck at login page like before. Second option of redirectOptions helps but all this happened while on ssr. I did not turn off ssr at any point, Even when reporting the issue

R0N1n-dev commented 1 year ago

But anyway, it works. I imagine the issue will create more problems in applying middleware to other pages. Will wait for fixes