nuxt-modules / supabase

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

No storage option exists to persist the session, which may result in unexpected behavior when using auth. #188

Closed CareTiger closed 1 year ago

CareTiger commented 1 year ago

seeing this warning/information on starting the dev server. Not sure of the implications and what action needs to be taken. FYI - discussion thread on Supabase - Discord server

No storage option exists to persist the session, which may result in unexpected behavior when using auth. If you want to set persistSession to true, please provide a storage option or you may set persistSession to false to disable this warning.

my nuxi info-

- Operating System: Darwin
- Node Version:     v19.8.1
- Nuxt Version:     3.5.2
- Nitro Version:    2.4.1
- Package Manager:  npm@9.5.1
- Builder:          vite
- User Config:      typescript, colorMode, app, plugins, modules, googleFonts, routeRules, runtimeConfig, nitro, devtools, image, vite
- Runtime Modules:  @storyblok/nuxt@5.4.7, @nuxt/image-edge@1.0.0-28092818.5c21f4c, @nuxt/devtools@0.5.5, @nuxtjs/supabase@0.3.5, @nuxtjs/google-fonts@3.0.1, @formkit/nuxt@0.17.2, @nuxthq/ui@2.2.1, @pinia/nuxt@0.4.11, @pinia-plugin-persistedstate/nuxt@1.1.1, @vee-validate/nuxt@4.9.6
- Build Modules:    -
maximilian-schwarz commented 1 year ago

This warning is coming from the "@supabase/supabase-js" package. Because the "persistSession" is not set. For more information: https://supabase.com/docs/reference/javascript/release-notes

Add to your nuxt.config.ts the following:

supabase: {
  client: {
      auth: {
          persistSession: false //or true
      }
  }
}

After this change the warning is gone.

mitjans commented 1 year ago

@maximilian-schwarz what are the implications of setting persistSession to true or false? What was the default behaviour before?

j4w8n commented 1 year ago

This warning is coming from the "@supabase/supabase-js" package. Because the "persistSession" is not set. For more information: https://supabase.com/docs/reference/javascript/release-notes

Add to your nuxt.config.ts the following:

supabase: {
  client: {
      auth: {
          persistSession: false //or true
      }
  }
}

After this change the warning is gone.

You might do some thorough testing with that. I haven't delved into the code, but the library may be relying on this being true for the browser client.

CC: @mitjans

j4w8n commented 1 year ago

Yeah, this line would need persistSession to be true for the browser client.

https://github.com/nuxt-modules/supabase/blob/main/src/runtime/plugins/supabase.client.ts#L32

And if you're calling getSession at all in your own code, it would fail as well.

j4w8n commented 1 year ago

Looks like this was resolved in release 0.3.6

CareTiger commented 1 year ago

resolved in release 0.3.6.

tidusvn05 commented 1 year ago

same problem on latest version: 0.3.6

Screenshot 2023-06-03 at 12 42 38


j4w8n commented 1 year ago

same problem on latest version: 0.3.6

Screenshot 2023-06-03 at 12 42 38


  • Operating System: Darwin
  • Node Version: v18.16.0
  • Nuxt Version: 3.5.2
  • Nitro Version: 2.4.1
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: ssr, nitro, experimental, runtimeConfig, app, modules, piniaPersistedstate, css, tailwindcss, supabase
  • Runtime Modules: @pinia/nuxt@0.4.11, @pinia-plugin-persistedstate/nuxt@1.1.1, @nuxtjs/supabase@0.3.6, @nuxtjs/tailwindcss@6.7.0, @vueuse/nuxt@10.1.2, nuxt-icon@0.4.1
  • Build Modules: -

@tidusvn05 can you try 0.3.7? Someone found another portion of code which needed changed.

tidusvn05 commented 1 year ago

Thank for your feedback.

i was upgrade, but problem still exist.

Screenshot 2023-06-25 at 15 49 08

j4w8n commented 1 year ago

@tidusvn05 do you mind creating a new issue and showing your code for creating all of your supabase clients?

jetlej commented 1 year ago

I'm still getting this error despite putting the code in my nuxt.config.js.


didim1 commented 11 months ago

const supabase = createClient( process.env.NEXT_PUBLIC_SUPABASE_URL as string, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY as string, { auth: { persistSession: false } } );

hi im from the future :3

jetlej commented 11 months ago

@didim1 yes that did the trick! So you need to set it in each file you're using createClient() in, NOT in the nuxt.config.js file

Rohianon commented 11 months ago

@didim1 it really worked indeed. Thanks for this.

wiesson commented 11 months ago

Can anyone explain what persistSession does? In which case does it persist the session? Whats better for me, true or false?

j4w8n commented 11 months ago

Can anyone explain what persistSession does? In which case does it persist the session? Whats better for me, true or false?

When true, it uses a storage implementation supported by supabase - whether built-in or custom; which holds auth info.

When false, it uses memory to hold this info.

MariuzM commented 11 months ago

But when its true or not even used it stores the token in localStorage but why i'm still getting this error? Setting to false does not make sense because you wont get your token in localStorage

j4w8n commented 11 months ago

But when its true or not even used it stores the token in localStorage but why i'm still getting this error? Setting to false does not make sense because you wont get your token in localStorage

This would be unusual. Possible, I'm sure. Would need to see some code.

MariuzM commented 11 months ago

But when its true or not even used it stores the token in localStorage but why i'm still getting this error? Setting to false does not make sense because you wont get your token in localStorage

This would be unusual. Possible, I'm sure. Would need to see some code.

Yep sorry i'm using Next.js and forgot to set file use client

MariuzM commented 11 months ago

Or maybe i'm wrong im still testing this, damn so confusing

Basically in Next.js using client component in useEffect i'm calling await db.auth.getSession() and i get this error message, but only get this once after i started dev server, when doing refresh i dont get this printed anymore, but if i kill and start again then i get

No storage option exists to persist the session, which may result in unexpected behavior when using auth.
        If you want to set persistSession to true, please provide a storage option or you may set persistSession to false to disable this warning.
wiesson commented 11 months ago

I'm also using Nextjs and I also find it confusing 😅

MariuzM commented 11 months ago

So noticed, that because i have createClient not in useEffect then i get this issue and it does not matter that i have set component as client, but when i add this createClient in useEffect then it works fine, so go figure. Next.js is really becoming unstable

image
MariuzM commented 11 months ago

I have tested this on SolidStart getting same issue. It looks to me that for split second it tries to run the code on Server hence the error but i'm not really sure if this maybe is a package problem than framework?

toddsampson commented 11 months ago

I had the same issue and managed to get it working. I saw in another post related to running Supabase locally that there was an issue with supabase/studio:0.23.06. As such, if you fork https://github.com/supabase/cli and change line 23 in internal/utils/misc.go from StudioImage = "supabase/studio:v0.23.06" to StudioImage = "supabase/studio, run go build -o supabase . to build the binary file and then copy it over the existing node_modules/supabase/bin/supabase in your project and you should be good to go. Be sure to run npx supabase stop --no-backup before you run npx supabase start again. Not a real "fix" but it should get you up-and-running

Feel free to grab the updated binary or source from my fork to build it yourself: https://github.com/toddsampson/cli

louis030195 commented 10 months ago

This is really annoying because it's unclear whether it crashes the code or not, make debugging very painful

I use it in /app/something/router.ts:

import { Database } from '@/types_db';
import { createClient } from '@supabase/supabase-js';

export const runtime = 'edge'

const supabase = createClient<Database>(
  process.env.SUPABASE_URL!,
  process.env.SUPABASE_KEY!,
);
export async function GET(req: Request) {

}

Such a mess to know which client use in different context, got to try 10 different ways to create the client both in local and deployed on vercel and see if it work or not 😆😭

j4w8n commented 10 months ago

@louis030195 based on what I see in your code, you're running the client on the server-side. And since you're not using auth helpers here, or custom storage, you should be setting these three auth options for your client.

const options = {
  auth: {
    persistSession: false,
    autoRefreshToken: false,
    detectSessionInUrl: false
  }
}
justinekatebe69 commented 10 months ago

How this helps:

{
   global: { headers: { Authorization: req.headers.get("Authorization")! } },
   auth: {
    detectSessionInUrl: false,
    autoRefreshToken: false,
    persistSession: false,
   }
}