supabase icon indicating copy to clipboard operation
supabase copied to clipboard

The ability to define pages requiring authentication

Open lukaszflorczak opened this issue 1 year ago • 7 comments

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.

lukaszflorczak avatar Sep 28 '23 10:09 lukaszflorczak

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

Kiansa avatar Oct 12 '23 19:10 Kiansa

@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.

Drew-Macgibbon avatar Oct 16 '23 08:10 Drew-Macgibbon

i agree

thangtran118 avatar Oct 16 '23 10:10 thangtran118

+1

T-Zahil avatar Oct 18 '23 13:10 T-Zahil

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

richard-edwards avatar Nov 07 '23 14:11 richard-edwards

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*)*']
 }

luizzappa avatar Nov 24 '23 02:11 luizzappa

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

Kiansa avatar Apr 10 '24 11:04 Kiansa