Documentation for createClient doesn't match implementation? Bug in GoTrueClient.js?

In this doc 'with additional parameters' [1] is shows options persistSession in an 'auth object inside the options. Due to my browser environment not having localStorage, I'm trying to disable attempts to use it, so I'm setting persistSession to false. However, that doesn't stop the implementation from trying to access localStorage. Setting localStorage to null or something doesn't help either - it actually has to be set to something 'compatible', eg what I've ended up doing: ``` const supabase = globalThis.supabase.createClient(supabase_url, supabase_key, { persistSession: false, localStorage: { setItem: () => {}, getItem: () => {}, removeItem: () => {}, clear: () => {}, }, }); ``` Doing the same in an auth property as indicated in the docs, doesn't help, because of this line: https://github.com/supabase/gotrue-js/blob/master/src/GoTrueClient.ts#L99 ``` this.localStorage = settings.localStorage || globalThis.localStorage ``` In my environment attempting to access globalThis.localStorage generates an exception: ``` globalThis.localStorage Uncaught Exception { name: "NS_ERROR_NOT_AVAILABLE", message: "", result: 2147746065, ...8<... } ``` It seems like subsequent uses of this.localStorage are protected from being null but setting it to null in the settings doesn't have any effect (and, predictably, it isn't possible to assign null to globalThis.localStorage`), eg here:

export const getItemSynchronously = (storage: SupportedStorage, key: string): any | null => {
  const value = isBrowser() && storage?.getItem(key)

https://github.com/supabase/gotrue-js/blob/master/src/lib/helpers.ts#L62

I know my environment is somewhat unusual, but it seems like this is actually a bug (since localStorage cannot be nullish).

What do you think?

[1] https://supabase.com/docs/reference/javascript/next/initializing#with-additional-parameters
screenshot.png
You can initialize a new Supabase client using the createClient() method.
GitHub
An isomorphic Javascript library for GoTrue. Contribute to supabase/gotrue-js development by creating an account on GitHub.
Was this page helpful?