stadtwerke/innungsapp/apps/mobile/hooks/useAuth.ts

22 lines
446 B
TypeScript

import { useAuthStore } from '@/store/auth.store'
import { useRouter } from 'expo-router'
export function useAuth() {
const { session, orgId, role, signOut } = useAuthStore()
const router = useRouter()
async function handleSignOut() {
await signOut()
router.replace('/(auth)/login')
}
return {
session,
orgId,
role,
isAuthenticated: !!session,
isAdmin: role === 'admin',
signOut: handleSignOut,
}
}