supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
2.86k stars 220 forks source link

No storage option exists... warning spammed in Next 13. #787

Closed sannajammeh closed 11 months ago

sannajammeh commented 11 months ago

When using @supabase/auth-helpers-nextjs it is very redundant to always have to disable persistSession every time I create a new supabase client. Following your docs will produce this stream of warnings as new clients are created.

Please limit this warning to only happen once (as the helpers create a singleton this should not be very difficult). In development it should really only fire a single time when the project boots (first supabase client is created), subsequent creations shouldn't fire this warning at all.

This right here is not pleasant to work with:

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.
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.
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.
- wait compiling...
- event compiled client and server successfully in 1930 ms (1751 modules)
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.
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.
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.
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.
j4w8n commented 11 months ago

Can you clarify what you mean by "very redundant"? Are you saying that you have a bunch of projects you're creating, and you always have to set this option? Or something else?

This warning is meant to indicate that your current setup could cause negative side effects in your app and ought to be changed. Do you have a use case where this isn't true? Many devs have spent hours troubleshooting issues, only to find out they simply needed to set persistSession to false - so this is trying to alleviate that.

Does this warning usually happen with the server clients in your apps?

I'd imagine it would be difficult to run this check once for the whole codebase because there can be a few different clients - client, middleware, server. And we won't know the whole situation until each client is initialized.

sannajammeh commented 11 months ago

Can you clarify what you mean by "very redundant"? Are you saying that you have a bunch of projects you're creating, and you always have to set this option? Or something else?

This warning is meant to indicate that your current setup could cause negative side effects in your app and ought to be changed. Do you have a use case where this isn't true? Many devs have spent hours troubleshooting issues, only to find out they simply needed to set persistSession to false - so this is trying to alleviate that.

Does this warning usually happen with the server clients in your apps?

I'd imagine it would be difficult to run this check once for the whole codebase because there can be a few different clients - client, middleware, server. And we won't know the whole situation until each client is initialized.

To clarify, your docs state to instantiate the RSC client inside of an RSC. Meaning if I have 5 components fetching data, all those 5 needs that extra option of persistSession or the warnings won't go away.

You are correct, doing this project wise will result in side effects. My suggestion is to warn it once per singleton. So middelware shows once, then RSC instantiates as a singleton and shows again, subsequent instantiates will not show it.

The local solution for me is another factory function around your factory functions that sets it as default, this would solve it but makes the code a bit less extensible.

I suggest an update to the docs here: https://supabase.com/docs/guides/getting-started/tutorials/with-nextjs So each code snippet actually includes persistSession.

This could be seen as a bug or a docs issue depending on what you guys think is best.

sannajammeh commented 11 months ago

Or even better (though I guess this requires a bit of discussion), default to false on server. If that isn't already the case though.

I can't think of any edge cases where you'd actually want to persist to a fake local storage in NodeJS or Edge runtimes. If you do, that's an edge case and can be opted into by flipping the flag again.

j4w8n commented 11 months ago

Thanks for your feedback.

So what's interesting here is that the auth helpers use a common createSupabaseClient() which does have storage set, and persistSession is true. So I'm not sure why you're seeing these warnings. Unless, in addition to using the auth helper clients, you're creating your own one-off native clients for certain things.

Can you share a minimum repo that has the issue?

tidusvn05 commented 11 months ago

i got same problem on nuxt3 project when update new version. and today i also use supabase edge functions with simple example.

import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm'

export const supabase = createClient(
  Deno.env.get('SUPABASE_URL') ?? '',
  Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''
)

Screenshot 2023-06-12 at 17 32 45

And the problem still same.

j4w8n commented 11 months ago

@tidusvn05 thanks for the feedback.

For the native client in the edge function, you can pass the persistSession auth option of false.

sannajammeh commented 11 months ago

Managed to resolve the issue. Closing.

tomelliot commented 9 months ago

@sannajammeh what resolution did you use?