fix: add login event actions

This commit is contained in:
yassinedorbozgithub 2025-01-30 11:24:19 +01:00
parent aebeeb1f59
commit a1b9bfcba0
3 changed files with 10 additions and 0 deletions

View File

@ -101,6 +101,10 @@ export const AuthProvider = ({ children }: AuthProviderProps): JSX.Element => {
}; };
const isAuthenticated = !!user; const isAuthenticated = !!user;
useSubscribeBroadcastChannel("login", () => {
router.reload();
});
useSubscribeBroadcastChannel("logout", () => { useSubscribeBroadcastChannel("logout", () => {
router.reload(); router.reload();
}); });

View File

@ -18,6 +18,7 @@ import {
import { generateId } from "@/utils/generateId"; import { generateId } from "@/utils/generateId";
export enum EBCEvent { export enum EBCEvent {
LOGIN = "login",
LOGOUT = "logout", LOGOUT = "logout",
} }

View File

@ -33,12 +33,17 @@ export const useLogin = (
>, >,
) => { ) => {
const { apiClient } = useApiClient(); const { apiClient } = useApiClient();
const { postMessage } = useBroadcastChannel();
return useMutation({ return useMutation({
...options, ...options,
async mutationFn(credentials) { async mutationFn(credentials) {
return await apiClient.login(credentials); return await apiClient.login(credentials);
}, },
onSuccess: (data, variables, context) => {
options?.onSuccess?.(data, variables, context);
postMessage({ event: "login" });
},
}); });
}; };