/** * useAuthenticatedUser * * Reactive reader for the AuthenticatedUser global — any component that calls * this re-renders when the store patches or clears the user. The single entry * point for "what's the current user / currency / completeness state". * * Returns `null` when signed out. Guards that need to redirect should pair * this with `tokenStorage.hasTokens()`. * * (c) 2026 TWWIM UG. All rights reserved. (www.twwim.com) */ import { useSyncExternalStore } from 'react'; import { authenticatedUserStore } from '@/infrastructure/storage/AuthenticatedUserStore'; import type { AuthenticatedUser } from '@/domain/entities/AuthenticatedUser'; const serverSnapshot = (): AuthenticatedUser | null => null; export function useAuthenticatedUser(): AuthenticatedUser | null { return useSyncExternalStore(authenticatedUserStore.subscribe, authenticatedUserStore.get, serverSnapshot); }