ultisuite-client/lib/hooks/use-chrome-identity.ts
R3D347HR4Y 9ea2d3325d
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
feat(auth): enhance authentication flows with embedded support and UI improvements
- Updated login and signup components to utilize AuthCard for better user experience during redirection.
- Introduced AuthentikEmbedDialog for seamless integration of Authentik's identity portal within the application.
- Enhanced password recovery and signup flows with dynamic theme handling and improved loading states.
- Refactored existing components to streamline authentication processes and improve maintainability.
2026-06-21 00:12:45 +02:00

59 lines
1.8 KiB
TypeScript

"use client"
import { usePersistHydrated } from "@/hooks/use-persist-hydrated"
import { useAuthStore } from "@/lib/api/auth-store"
import { useCurrentUser } from "@/lib/api/hooks/use-current-user"
import { useAccountStore, useActiveAccount } from "@/lib/stores/account-store"
import { DEMO_USER } from "@/components/demo/demo-mail-data"
import { useIsDemoApp } from "@/lib/demo/use-is-demo-app"
/** Identity shown in header avatar / account menu (OIDC user, else active mail account). */
export function useChromeIdentity(): {
name: string
email: string
firstName: string
avatarUrl?: string
} | null {
const isDemoApp = useIsDemoApp()
const authHydrated = usePersistHydrated(useAuthStore)
const accountHydrated = usePersistHydrated(useAccountStore)
const isAuthenticated = useAuthStore((s) => s.isAuthenticated())
const platformUser = useAuthStore((s) => s.user)
const mailAccount = useActiveAccount()
const { data: currentUser } = useCurrentUser()
if (isDemoApp) {
return {
name: DEMO_USER.name,
email: DEMO_USER.email,
firstName: DEMO_USER.name.split(/\s+/)[0] ?? DEMO_USER.name,
}
}
// Keep SSR and first client render identical until persist stores rehydrate.
if (!authHydrated) return null
if (!isAuthenticated) return null
if (!platformUser && !accountHydrated) return null
if (platformUser) {
return {
name: platformUser.name,
email: platformUser.email,
firstName: platformUser.firstName,
avatarUrl: currentUser?.avatar_url,
}
}
if (mailAccount) {
const firstName = mailAccount.name.split(/\s+/)[0] ?? mailAccount.name
return {
name: mailAccount.name,
email: mailAccount.email,
firstName,
avatarUrl: mailAccount.avatarUrl,
}
}
return null
}