mirror of
https://github.com/hexastack/hexabot
synced 2025-02-23 12:59:14 +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;
|
||||
|
||||
useSubscribeBroadcastChannel("login", () => {
|
||||
router.reload();
|
||||
});
|
||||
|
||||
useSubscribeBroadcastChannel("logout", () => {
|
||||
router.reload();
|
||||
});
|
||||
|
@ -18,6 +18,7 @@ import {
|
||||
import { generateId } from "@/utils/generateId";
|
||||
|
||||
export enum EBCEvent {
|
||||
LOGIN = "login",
|
||||
LOGOUT = "logout",
|
||||
}
|
||||
|
||||
|
@ -33,12 +33,17 @@ export const useLogin = (
|
||||
>,
|
||||
) => {
|
||||
const { apiClient } = useApiClient();
|
||||
const { postMessage } = useBroadcastChannel();
|
||||
|
||||
return useMutation({
|
||||
...options,
|
||||
async mutationFn(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