fix auth bug [FE]
This commit is contained in:
parent
7391f6f85d
commit
ba2826484f
1 changed files with 8 additions and 5 deletions
|
|
@ -14,16 +14,23 @@ const state = reactive<AuthState>({
|
||||||
const AUTH_KEY = 'crimata_token';
|
const AUTH_KEY = 'crimata_token';
|
||||||
|
|
||||||
const token = window.localStorage.getItem(AUTH_KEY);
|
const token = window.localStorage.getItem(AUTH_KEY);
|
||||||
|
if (token) {
|
||||||
|
state.accessToken = token;
|
||||||
|
window.localStorage.setItem(AUTH_KEY, token);
|
||||||
|
}
|
||||||
|
|
||||||
const authToken = async () => {
|
const authToken = async () => {
|
||||||
const { invoke } = useIpc();
|
const { invoke } = useIpc();
|
||||||
try {
|
try {
|
||||||
state.accessToken = await invoke('auth-session', token);
|
const res = await invoke('auth-session', token);
|
||||||
|
window.localStorage.setItem(AUTH_KEY, res);
|
||||||
|
state.accessToken = res;
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
state.error = e;
|
state.error = e;
|
||||||
console.log('ERROR: failed authentication');
|
console.log('ERROR: failed authentication');
|
||||||
window.localStorage.removeItem(AUTH_KEY);
|
window.localStorage.removeItem(AUTH_KEY);
|
||||||
|
state.accessToken = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,10 +39,6 @@ window.ipcRenderer.on("auth", async (_event, _arg) => {
|
||||||
await authToken();
|
await authToken();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (token) {
|
|
||||||
state.accessToken = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAuth = () => {
|
export const useAuth = () => {
|
||||||
|
|
||||||
const setToken = (token: string) => {
|
const setToken = (token: string) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue