-
Notifications
You must be signed in to change notification settings - Fork 132
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
Reactive Native and AsyncAuthStore example issue. #249
Comments
I don't think this is specific to PocketBase or the SDK. From the MDN
Depending on your environment and the targeted platform, you can try to add If that doesn't work, note that it is not required to load the initial state with the constructor and you can set it with the resolve of the import AsyncStorage from '@react-native-async-storage/async-storage';
import PocketBase, { AsyncAuthStore } from 'pocketbase';
const store = new AsyncAuthStore({
save: async (serialized) => AsyncStorage.setItem('pb_auth', serialized),
});
AsyncStorage.getItem('pb_auth').then((value) => {
// if exist `value` should be a serialized json
try {
const parsed = JSON.parse(value) || {};
store.save(parsed.token || "", parsed.model || null);
} catch (_) {}
})
const pb = new PocketBase('http://127.0.0.1:8090', store) If neither of the suggested 2 options work, feel free to provide more details about your environment (eg. what Node.js and React Native versions you use, what platform you target, do you use expo, etc.) and I'll try to have a more detailed look at it. |
Thank you for the response @ganigeorgiev. The promise resolve route worked. My env:
Confirmed it works for
|
I'll consider with the next release to add support for both const store = new AsyncAuthStore({
save: async (serialized) => AsyncStorage.setItem('pb_auth', serialized),
initial: AsyncStorage.getItem('pb_auth'),
}); |
Tried this in react native but running into top level await not supported issues. Has anyone tried this and got it working in react native? Any suggestions or an example of getting a store for pocketbase working in react native would be great!
The text was updated successfully, but these errors were encountered: