Add password change flow and auth error handling

- Add ChangePasswordPage component for forced password changes
- Add RequirePasswordChange wrapper in App.tsx to redirect users
- Add custom error classes (UnauthorizedError, ForbiddenError) in api.ts
- Add 401/403 error handling in ProjectPage and PackagePage
- Add refreshUser function to AuthContext
- Add must_change_password field to User type
- Add access denied UI for forbidden resources
This commit is contained in:
Mondo Diaz
2026-01-09 13:14:05 -06:00
parent 6b9f63a30e
commit 3ebdf51105
8 changed files with 330 additions and 20 deletions

View File

@@ -8,6 +8,7 @@ interface AuthContextType {
error: string | null;
login: (username: string, password: string) => Promise<void>;
logout: () => Promise<void>;
refreshUser: () => Promise<void>;
clearError: () => void;
}
@@ -71,8 +72,17 @@ export function AuthProvider({ children }: AuthProviderProps) {
setError(null);
}, []);
const refreshUser = useCallback(async () => {
try {
const currentUser = await getCurrentUser();
setUser(currentUser);
} catch {
setUser(null);
}
}, []);
return (
<AuthContext.Provider value={{ user, loading, error, login, logout, clearError }}>
<AuthContext.Provider value={{ user, loading, error, login, logout, refreshUser, clearError }}>
{children}
</AuthContext.Provider>
);