nuxt-modules / supabase

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

Everything to be excluded in redirectOptions except one folder #268

Closed KosyoK1104 closed 1 year ago

KosyoK1104 commented 1 year ago

Hello guys, I am trying to make sure the authentication check if the user is logged in to be applicable to only one folder and every other to be excluded from it. Should I use some regex if it is possible? Or should I write down every route that should be excluded?

larbish commented 1 year ago

Indeed currently you can only specified routes to exclude from the redirection process. So you need to specify all the "public" routes in the exclude option.

davidparys commented 1 year ago

Indeed currently you can only specified routes to exclude from the redirection process. So you need to specify all the "public" routes in the exclude option.

I'm running onto something similar. Isn't there a hacky way to exclude all but include one single page? I have a very complex structure and I only need one /dashboard page, seems a little bit hectic to have to add all of them.

larbish commented 1 year ago

I think the best way to handle this is to disable the redirect option and do the redirection yourself in the concerned page with a simple middleware. If you disable the redirect option, you'll need to configure the callback url for auth as a client rendered route. You can check what this option set under the hood here and here. Hope it helps!

luizzappa commented 11 months ago

@davidparys , a dirty trick 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

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

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

I understand that this is has a low priority, but in my opinion this is a valid feature request. Don't you think @larbish?

I'd argue that this issue should be re-opened. My approach would be to add an optional include property, basically doing the exact opposite of the exclude property.

larbish commented 8 months ago

@jojomatik I agree. Feel free to create a PR, I'll be happy to merge it asap.

jojomatik commented 8 months ago

Here you go #336