-
Notifications
You must be signed in to change notification settings - Fork 466
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
not working react native web #1096
Comments
Got the exact same issue. |
Got the exact same issue. Using: |
Here's a workaround if you are using something like Zustand: // Zustand Store
{
...,
storage: createJSONStorage(() =>
Platform.OS === "web" ? localStorage : AsyncStorage
),
...,
} |
localStorage ? |
For those using supabase and seeing this in the stack trace too, check out supabase/supabase-js#786 |
@adsalihac At least, Zustand is able to deal with that seamlessly. |
i am using redux with presist , it is support ? @t1gu1 , also what about Zustand , it is better than redux ? |
@adsalihac Nope Redux is more complexe on that side. We migrate all our project to use Zustand cause it's stupid easy to use and works really well! |
what about state migration in zustand (like version update) , which zustand is using , official module right ? it is possible to get data like this (store.getState()?.auth?.user) ? |
@adsalihac Yes and yes. |
Thank you @t1gu1 |
I think I encountered the same problem. Using: ios error message [ReferenceError: Can't find variable: localStorage] |
Upgrade Expo package: (Just to be sure)
Where you create your Zustand store, simply add that for the storage: Use |
Confirmed the same issue
|
For me it seems like this issue can be close. |
some issue here with 2.0.0 version |
I'm having the same issue... Latest expo sdk and react-native-async-storage version |
Great! I solve it by the following code. import { AppState, Platform } from 'react-native';
import 'react-native-url-polyfill/auto';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = process.env.EXPO_PUBLIC_SUPABASE_URL;
const supabaseAnonKey = process.env.EXPO_PUBLIC_SUPABASE_ANON_KEY;
if (!supabaseUrl || !supabaseAnonKey) {
throw new Error('Supabase URL or Anon Key is not defined');
}
class SupabaseStorage {
async getItem(key: string) {
if (Platform.OS === "web") {
if (typeof localStorage === "undefined") {
return null;
}
return localStorage.getItem(key);
}
return AsyncStorage.getItem(key);
}
async removeItem(key: string) {
if (Platform.OS === "web") {
return localStorage.removeItem(key);
}
return AsyncStorage.removeItem(key);
}
async setItem(key: string, value: string) {
if (Platform.OS === "web") {
return localStorage.setItem(key, value);
}
return AsyncStorage.setItem(key, value);
}
}
export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
auth: {
storage: new SupabaseStorage(),
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: false,
},
}); |
Window cannot be used, otherwise localstorage |
What happened?
Getting Error
Version
1.23.1
What platforms are you seeing this issue on?
System Information
Steps to Reproduce
The text was updated successfully, but these errors were encountered: