feat: Implement initial with admin and mobile clients, authentication, data models, and lead generation scripts.

This commit is contained in:
2026-02-19 16:18:34 +01:00
parent c53a71a5f9
commit 5e2d5fb3ae
32 changed files with 2283 additions and 420 deletions

View File

@@ -1,5 +1,6 @@
import { create } from 'zustand'
import { MOCK_MEMBER_ME } from '@/lib/mock-data'
import { authClient } from '@/lib/auth-client'
import AsyncStorage from '@react-native-async-storage/async-storage'
interface Session {
user: { id: string; email: string; name: string }
@@ -9,26 +10,48 @@ interface AuthState {
session: Session | null
isInitialized: boolean
initialize: () => Promise<void>
setSession: (session: Session | null, token?: string) => Promise<void>
signOut: () => Promise<void>
}
export const useAuthStore = create<AuthState>((set) => ({
// Mock: direkt eingeloggt
session: {
user: {
id: MOCK_MEMBER_ME.userId!,
email: MOCK_MEMBER_ME.email,
name: MOCK_MEMBER_ME.name,
},
},
isInitialized: true,
session: null,
isInitialized: false,
initialize: async () => {
// Mock: nichts zu tun
set({ isInitialized: true })
try {
// Check if we have a stored token and validate it
const token = await AsyncStorage.getItem('better-auth-session')
if (!token) {
set({ session: null, isInitialized: true })
return
}
// authClient now sends the token via cookie header (see auth-client.ts)
const result = await authClient.getSession()
if (result?.data?.user) {
set({
session: { user: result.data.user },
isInitialized: true,
})
} else {
await AsyncStorage.removeItem('better-auth-session')
set({ session: null, isInitialized: true })
}
} catch {
set({ session: null, isInitialized: true })
}
},
setSession: async (session, token) => {
if (token) {
await AsyncStorage.setItem('better-auth-session', token)
}
set({ session })
},
signOut: async () => {
await authClient.signOut()
await AsyncStorage.removeItem('better-auth-session')
set({ session: null })
},
}))