nuxt-modules / supabase

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

The ability to define pages requiring authentication #280

Open lukaszflorczak opened 1 year ago

lukaszflorczak commented 1 year ago

Each time a user is trying to access a page that needs authentication, he will automatically be redirected to the configured log in page. If you want to allow access to "public" page, you just need to add them in the exclude redirect option.

I believe that it would be highly beneficial to have an option that serves as the opposite of the 'exclude' param. In my specific use case, I have numerous public pages, including multiple versions of landing pages that are directly accessible from the root (/landing-page-name). Consequently, excluding them using wildcards seems to be impossible. On the other hand, there is only one URL (/dashboard/**) that requires authentication.

Kiansa commented 1 year ago

I'm having the same issue. having an include option would be great!

Drew-Macgibbon commented 1 year ago

@lukaszflorczak I agree, this is a common issue I've run into multiple times.

Having a useAuth boolean in the config would also be nice for websites that don't require auth.

However, I have found that exclude: ['/*'] also does the trick.

thangtran118 commented 1 year ago

i agree

T-Zahil commented 1 year ago

+1

richard-edwards commented 1 year ago

I totally agree. I want everything under /app/ to require auth and nothing else so an include option is a must.

luizzappa commented 11 months ago

Up for this feature!

For now a workaround is to reverse engineer this regex here to behave like an include:

https://github.com/nuxt-modules/supabase/blob/0294a01cf71f10dad49679a4443eb224c4ec92bf/src/runtime/plugins/auth-redirect.ts#L15

For instance, If you only need the /dashboard path to be considered, use this pattern in nuxt.config:

{
   exclude: ['(?!*\/dashboard*)*']
 }
Kiansa commented 7 months ago

I just saw that it's implemented. now you can use include:

  redirectOptions: {
    login: '/login',
    callback: '/confirm',
    include: ['/dashboard(/*)?'],
  }

" include: Routes to include in the redirect. ['/dashboard(/*)?'] will enable the redirect only for the dashboard page and all sub-pages. " https://supabase.nuxtjs.org/get-started#redirectoptions