({
children,
onProviderChange,
}: ProviderComponentProps)
| 54 | |
| 55 | // Local auth provider for development |
| 56 | const LocalAuthProvider: FrontendAuthProviderComponent = ({ |
| 57 | children, |
| 58 | onProviderChange, |
| 59 | }: ProviderComponentProps) => { |
| 60 | // Access auth store state |
| 61 | const adminUsername = useAuthStore((state) => state.adminUsername); |
| 62 | const adminPassword = useAuthStore((state) => state.adminPassword); |
| 63 | const userId = useAuthStore((state) => state.userId); |
| 64 | const organizationId = useAuthStore((state) => state.organizationId); |
| 65 | |
| 66 | // Create provider that reacts to store state |
| 67 | const localProvider = useMemo<FrontendAuthProvider>(() => { |
| 68 | const hasCredentials = !!(adminUsername && adminPassword); |
| 69 | |
| 70 | return { |
| 71 | name: 'local', |
| 72 | context: { |
| 73 | user: hasCredentials |
| 74 | ? { |
| 75 | id: userId || 'admin', |
| 76 | organizationId: organizationId || 'local-dev', |
| 77 | organizationRole: 'ADMIN', |
| 78 | } |
| 79 | : null, |
| 80 | token: hasCredentials |
| 81 | ? { |
| 82 | token: `basic-${btoa(`${adminUsername}:${adminPassword}`)}`, |
| 83 | expiresAt: undefined, |
| 84 | } |
| 85 | : null, |
| 86 | isLoading: false, |
| 87 | isAuthenticated: hasCredentials, |
| 88 | error: null, |
| 89 | }, |
| 90 | signIn: () => { |
| 91 | console.warn('Local auth: signIn not implemented - use AdminLoginForm'); |
| 92 | }, |
| 93 | signUp: () => { |
| 94 | console.warn('Local auth: signUp not implemented'); |
| 95 | }, |
| 96 | signOut: async () => { |
| 97 | // Clear session cookie via backend logout endpoint |
| 98 | // Use relative path to ensure we hit the same origin as login |
| 99 | try { |
| 100 | await fetch('/api/v1/auth/logout', { |
| 101 | method: 'POST', |
| 102 | credentials: 'include', |
| 103 | }); |
| 104 | } catch (error) { |
| 105 | console.warn('Failed to clear session cookie:', error); |
| 106 | } |
| 107 | // Clear admin credentials from store |
| 108 | useAuthStore.getState().clear(); |
| 109 | }, |
| 110 | SignInComponent: () => <div>Sign in not available in local dev mode</div>, |
| 111 | SignUpComponent: () => <div>Sign up not available in local dev mode</div>, |
| 112 | UserButtonComponent: () => <div>User profile not available in local dev mode</div>, |
| 113 | OrganizationSwitcherComponent: undefined, |
nothing calls this directly
no test coverage detected