feat : Structure de base

This commit is contained in:
Yaël Perret
2026-09-02 11:31:58 +02:00
parent 68d7ea3f9a
commit 4f8596881c
22 changed files with 579 additions and 2 deletions

39
src/stores/authStore.ts Normal file
View File

@@ -0,0 +1,39 @@
import * as SecureStore from 'expo-secure-store';
import { create } from 'zustand';
export type Role = 'user' | 'org';
export type Session = {
userId: string;
token: string;
role: Role;
}
type AuthState = {
session: Session | null;
hydrated: boolean; // Le disque a été lu, la réponse est fiable
hydrate: () => Promise<void>;
signIn: (session: Session) => Promise<void>;
signOut: () => Promise<void>;
};
const KEY = 'bahla.session';
export const useAuth = create<AuthState>((set) => ({
session: null,
hydrated: false,
hydrate: async () => {
const session = await SecureStore.getItemAsync(KEY);
set({ session: session ? JSON.parse(session) : null, hydrated: true });
},
signIn: async (s: Session) => {
await SecureStore.setItemAsync(KEY, JSON.stringify(s));
set({ session: s });
},
signOut: async () => {
await SecureStore.deleteItemAsync(KEY);
set({ session: null });
},
}));