's'
This commit is contained in:
29
lib/authStorage.ts
Normal file
29
lib/authStorage.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||
import type { PbUserRecord } from './pocketbase'
|
||||
|
||||
const KEY = 'pb_auth_session_v1'
|
||||
|
||||
export type StoredPbSession = {
|
||||
token: string
|
||||
record: PbUserRecord
|
||||
}
|
||||
|
||||
export async function loadPbSession(): Promise<StoredPbSession | null> {
|
||||
try {
|
||||
const raw = await AsyncStorage.getItem(KEY)
|
||||
if (!raw) return null
|
||||
const j = JSON.parse(raw) as StoredPbSession
|
||||
if (!j?.token || !j?.record?.id) return null
|
||||
return j
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function savePbSession(s: StoredPbSession): Promise<void> {
|
||||
await AsyncStorage.setItem(KEY, JSON.stringify(s))
|
||||
}
|
||||
|
||||
export async function clearPbSession(): Promise<void> {
|
||||
await AsyncStorage.removeItem(KEY)
|
||||
}
|
||||
Reference in New Issue
Block a user