Skip to content

authstore null in react native #4787

Closed Answered by ganigeorgiev
apujayed asked this question in Q&A
Discussion options

You must be logged in to vote

You are creating 2 different PocketBase instances, and the one in your Home component doesn't use the store defined in handleLogin.

Move the SDK initialization in a new js file (when using the JS SDK instance on the client-side it is safe to have a single global instance):

// src/pb.js

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),
  initial: AsyncStorage.getItem('pb_auth'),
})

const pb = new PocketBase('https://serverurl.com', store)

export default pb

And then you can simply import it your compon…

Replies: 2 comments 10 replies

Comment options

You must be logged in to vote
3 replies
@apujayed
Comment options

@ganigeorgiev
Comment options

Answer selected by apujayed
@apujayed
Comment options

Comment options

You must be logged in to vote
7 replies
@ganigeorgiev
Comment options

@ganigeorgiev
Comment options

@ganigeorgiev
Comment options

@baltazar-gr
Comment options

@ganigeorgiev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants