add authenticate on socket connect

This commit is contained in:
Enrique Hernandez 2021-02-09 17:07:45 -06:00
commit e0da50eb27
7 changed files with 112 additions and 70 deletions

View file

@ -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;