New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local Storage problem on React Native (MMKV cache) #6348
Comments
For anyone who is keen, the workaround that I came up with for using MMKV as cache which helps to remove the errors and warnings
|
Thanks for the workaround @lyqht . I'll close this since you've shared that snippet! To answer your question:
The auth library simply uses the
|
In case helpful, here an example with export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
localStorage: AsyncStorage as any,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
}); |
For anyone using import { SUPABASE_URL, SUPABASE_ANON_KEY } from './constants';
import { createClient } from "@supabase/supabase-js";
import { MMKV } from 'react-native-mmkv'
const storage = new MMKV({ id: 'supabase-storage' })
const mmkvStorageConfig = {
setItem: (key, data) => storage.set(key, data),
getItem: (key) => storage.getString(key),
removeItem: (key) => storage.delete(key),
}
export const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
localStorage: mmkvStorageConfig,
persistSession: true,
autoRefreshToken: true,
detectSessionInUrl: false
}); |
in typescript import 'react-native-url-polyfill/auto';
import { SupportedStorage, createClient } from '@supabase/supabase-js';
import { MMKV } from 'react-native-mmkv';
const storage = new MMKV({ id: 'supabase-storage' });
const mmkvSupabaseSupportedStorage = {
setItem: (key, data) => storage.set(key, data),
getItem: (key) => storage.getString(key) ?? null,
removeItem: (key) => storage.delete(key),
} satisfies SupportedStorage;
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
storage: mmkvSupabaseSupportedStorage,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
}); |
Bug report
Describe the bug
This bug is pretty similar to what is reported in #276, where I'm getting errors like
So far I have developed the login and sign up functionality for my app by ignoring the error, but now that I'm trying to implement the sign out functionality, the following warning stops me from proceeding any further.
The solution in #276 is to declare the storage manually as async storage, however I'm using MMKV for storage instead.
I will get the following typescript prompt when I try to set the storage as MMKV.
Reading the documentation on initializing the client further, I also tried the following configuration to create the client, but it still tries to access this.localStorage.
Do I have to swap out my cache provider entirely? or is there a way to work around this? Any help will be appreciated!
To Reproduce
Reference project can be found at Billy.
Expected behavior
System information
The text was updated successfully, but these errors were encountered: