- PRD: vollständige Produktspezifikation (5 Module, Scope, Akzeptanzkriterien) - ARCHITECTURE: Tech Stack, Ordnerstruktur, Multi-Tenancy, Push, Kosten - DATABASE_SCHEMA: Vollständiges SQL-Schema mit RLS Policies und Views - USER_STORIES: 40+ Stories nach Rolle (Admin, Mitglied, Azubi, Obermeister) - PERSONAS: 5 detaillierte Nutzerprofile mit Alltag, Zitaten und Erwartungen - BUSINESS_MODEL: Preistabellen, Unit Economics, Revenue-Projektionen, Distribution - ROADMAP: 6 Phasen, Sprint-Planung, Meilensteine und KPIs - COMPETITIVE_ANALYSIS: Wettbewerbsmatrix, USPs, Preispositionierung - API_DESIGN: Supabase Query Patterns, Edge Functions, Realtime Subscriptions - ONBOARDING_FLOWS: 7 User Flows von Setup bis Fehlerfall - GTM_STRATEGY: 3-Phasen-Vertrieb, Outreach-Sequenz, Einwandbehandlung - AZUBI_MODULE: Video-Feed, 1-Click-Apply, Chat, Berichtsheft, Quiz - DSGVO_KONZEPT: Rechtsgrundlagen, TOMs, AVV, Minderjährige, Incident Response - FEATURES_BACKLOG: 72 Features nach MoSCoW + Technische Schulden Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import { create } from 'zustand'
|
|
import { authClient } from '@/lib/auth-client'
|
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
|
|
interface Session {
|
|
user: {
|
|
id: string
|
|
email: string
|
|
name: string
|
|
}
|
|
token?: string
|
|
}
|
|
|
|
interface AuthState {
|
|
session: Session | null
|
|
orgId: string | null
|
|
role: 'admin' | 'member' | null
|
|
isInitialized: boolean
|
|
initialize: () => Promise<void>
|
|
setSession: (session: Session | null) => void
|
|
signOut: () => Promise<void>
|
|
}
|
|
|
|
export const useAuthStore = create<AuthState>((set) => ({
|
|
session: null,
|
|
orgId: null,
|
|
role: null,
|
|
isInitialized: false,
|
|
|
|
initialize: async () => {
|
|
try {
|
|
const { data } = await authClient.getSession()
|
|
if (data?.session && data?.user) {
|
|
set({
|
|
session: { user: data.user },
|
|
isInitialized: true,
|
|
})
|
|
// Store token for API requests
|
|
if (data.session.token) {
|
|
await AsyncStorage.setItem('better-auth-session', data.session.token)
|
|
}
|
|
} else {
|
|
await AsyncStorage.removeItem('better-auth-session')
|
|
set({ session: null, orgId: null, role: null, isInitialized: true })
|
|
}
|
|
} catch {
|
|
set({ session: null, isInitialized: true })
|
|
}
|
|
},
|
|
|
|
setSession: (session) => set({ session }),
|
|
|
|
signOut: async () => {
|
|
await authClient.signOut()
|
|
await AsyncStorage.removeItem('better-auth-session')
|
|
set({ session: null, orgId: null, role: null })
|
|
},
|
|
}))
|