mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
18 lines
577 B
TypeScript
18 lines
577 B
TypeScript
import { useAppDispatch, useAppSelector } from '../../../store/hooks';
|
|
import { loginSuccess, logout as logoutAction, hydrateAuth } from '../store/auth.slice';
|
|
import type { LoginPayload } from '../types/auth.types';
|
|
|
|
export function useAuth() {
|
|
const dispatch = useAppDispatch();
|
|
const { user, token, isAuthenticated } = useAppSelector((s) => s.auth);
|
|
|
|
return {
|
|
user,
|
|
token,
|
|
isAuthenticated,
|
|
login: (payload: LoginPayload) => dispatch(loginSuccess(payload)),
|
|
logout: () => dispatch(logoutAction()),
|
|
hydrate: () => dispatch(hydrateAuth()),
|
|
};
|
|
}
|