feat: Implement initial with admin and mobile clients, authentication, data models, and lead generation scripts.
This commit is contained in:
@@ -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 })
|
||||
},
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user