ui creation
This commit is contained in:
20
src/auth/authContext.ts
Normal file
20
src/auth/authContext.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { createContext, useContext } from 'react';
|
||||
import type { AuthState } from './keycloak';
|
||||
|
||||
export type AuthContextValue = AuthState & {
|
||||
login: () => Promise<void>;
|
||||
logout: () => Promise<void>;
|
||||
};
|
||||
|
||||
export const AuthContext = createContext<AuthContextValue | null>(null);
|
||||
|
||||
/** Дает компонентам доступ к данным пользователя и действиям login/logout. */
|
||||
export function useAuth(): AuthContextValue {
|
||||
const context = useContext(AuthContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error('useAuth must be used within AuthProvider');
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user