mirror of
https://github.com/hexastack/hexabot
synced 2025-02-23 04:48:51 +00:00
fix: add login event actions
This commit is contained in:
parent
aebeeb1f59
commit
a1b9bfcba0
@ -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();
|
||||||
});
|
});
|
||||||
|
@ -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",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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" });
|
||||||
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user