mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
Merge branch 'feature/user-profile' of github.com:hydralauncher/hydra into feature/user-profile
This commit is contained in:
commit
b3e2346808
4 changed files with 7 additions and 7 deletions
|
@ -2,11 +2,11 @@ import { userAuthRepository } from "@main/repository";
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import { HydraApi } from "@main/services/hydra-api";
|
import { HydraApi } from "@main/services/hydra-api";
|
||||||
|
|
||||||
const signout = async (_event: Electron.IpcMainInvokeEvent): Promise<void> => {
|
const signOut = async (_event: Electron.IpcMainInvokeEvent): Promise<void> => {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
userAuthRepository.delete({ id: 1 }),
|
userAuthRepository.delete({ id: 1 }),
|
||||||
HydraApi.post("/auth/logout"),
|
HydraApi.post("/auth/logout"),
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
registerEvent("signout", signout);
|
registerEvent("signOut", signOut);
|
||||||
|
|
|
@ -133,7 +133,7 @@ contextBridge.exposeInMainWorld("electron", {
|
||||||
getUser: (userId: string) => ipcRenderer.invoke("getUser", userId),
|
getUser: (userId: string) => ipcRenderer.invoke("getUser", userId),
|
||||||
|
|
||||||
/* Auth */
|
/* Auth */
|
||||||
signout: () => ipcRenderer.invoke("signout"),
|
signOut: () => ipcRenderer.invoke("signOut"),
|
||||||
onSignIn: (cb: () => void) => {
|
onSignIn: (cb: () => void) => {
|
||||||
const listener = (_event: Electron.IpcRendererEvent) => cb();
|
const listener = (_event: Electron.IpcRendererEvent) => cb();
|
||||||
ipcRenderer.on("on-signin", listener);
|
ipcRenderer.on("on-signin", listener);
|
||||||
|
|
2
src/renderer/src/declaration.d.ts
vendored
2
src/renderer/src/declaration.d.ts
vendored
|
@ -112,7 +112,7 @@ declare global {
|
||||||
restartAndInstallUpdate: () => Promise<void>;
|
restartAndInstallUpdate: () => Promise<void>;
|
||||||
|
|
||||||
/* Authg */
|
/* Authg */
|
||||||
signout: () => Promise<void>;
|
signOut: () => Promise<void>;
|
||||||
onSignIn: (cb: () => void) => () => Electron.IpcRenderer;
|
onSignIn: (cb: () => void) => () => Electron.IpcRenderer;
|
||||||
onSignOut: (cb: () => void) => () => Electron.IpcRenderer;
|
onSignOut: (cb: () => void) => () => Electron.IpcRenderer;
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,13 @@ import { setUserAuth } from "@renderer/features";
|
||||||
export function useUserAuth() {
|
export function useUserAuth() {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
const { userAuth } = useAppSelector((state) => state.userAuth);
|
const { userAuth } = useAppSelector((state) => state.userAuth);
|
||||||
|
|
||||||
const signOut = useCallback(async () => {
|
const signOut = useCallback(async () => {
|
||||||
dispatch(setUserAuth(null));
|
dispatch(setUserAuth(null));
|
||||||
return window.electron.signout();
|
return window.electron.signOut();
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
const updateUserAuth = useCallback(async () => {
|
const updateUserAuth = useCallback(async () => {
|
||||||
|
@ -27,7 +27,7 @@ export function useUserAuth() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
updateUserAuth();
|
updateUserAuth();
|
||||||
}, []);
|
}, [updateUserAuth]);
|
||||||
|
|
||||||
const clearUserAuth = useCallback(async () => {
|
const clearUserAuth = useCallback(async () => {
|
||||||
dispatch(setUserAuth(null));
|
dispatch(setUserAuth(null));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue