add authenticate on socket connect
This commit is contained in:
parent
4a9e19bb43
commit
e0da50eb27
7 changed files with 112 additions and 70 deletions
|
|
@ -24,10 +24,23 @@ const state = reactive<AuthState>({
|
|||
const AUTH_KEY = 'crimata_token';
|
||||
|
||||
const token = window.localStorage.getItem(AUTH_KEY);
|
||||
console.log('token: ',token)
|
||||
|
||||
// authenticate on socket connect
|
||||
window.ipcRenderer.on("fetch-token", async (event, payload) => {
|
||||
const { data, invoke } = useIpc('auth-token');
|
||||
try {
|
||||
await invoke(token);
|
||||
state.user = data.value;
|
||||
}
|
||||
catch(e) {
|
||||
state.error = e;
|
||||
console.log('ERROR: failed authentication');
|
||||
window.localStorage.removeItem(AUTH_KEY);
|
||||
}
|
||||
});
|
||||
|
||||
if (token) {
|
||||
const { loading, error, data, send } = useIpc('auth-user');
|
||||
const { loading, error, data, send, invoke } = useIpc('auth-user');
|
||||
|
||||
state.authenticating = true;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue