feat: Implement mobile application and lead processing utilities.
This commit is contained in:
@@ -1,58 +1,34 @@
|
||||
import { create } from 'zustand'
|
||||
import { authClient } from '@/lib/auth-client'
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||
import { MOCK_MEMBER_ME } from '@/lib/mock-data'
|
||||
|
||||
interface Session {
|
||||
user: {
|
||||
id: string
|
||||
email: string
|
||||
name: string
|
||||
}
|
||||
token?: string
|
||||
user: { id: string; email: string; name: 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,
|
||||
// Mock: direkt eingeloggt
|
||||
session: {
|
||||
user: {
|
||||
id: MOCK_MEMBER_ME.userId!,
|
||||
email: MOCK_MEMBER_ME.email,
|
||||
name: MOCK_MEMBER_ME.name,
|
||||
},
|
||||
},
|
||||
isInitialized: true,
|
||||
|
||||
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 })
|
||||
}
|
||||
// Mock: nichts zu tun
|
||||
set({ isInitialized: true })
|
||||
},
|
||||
|
||||
setSession: (session) => set({ session }),
|
||||
|
||||
signOut: async () => {
|
||||
await authClient.signOut()
|
||||
await AsyncStorage.removeItem('better-auth-session')
|
||||
set({ session: null, orgId: null, role: null })
|
||||
set({ session: null })
|
||||
},
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user