mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Clean up code and fix authentication
This commit is contained in:
@@ -18,11 +18,9 @@ app.whenReady().then(() => {
|
|||||||
titleBarOverlay: process.platform !== "darwin"
|
titleBarOverlay: process.platform !== "darwin"
|
||||||
})
|
})
|
||||||
|
|
||||||
// You can use `process.env.VITE_DEV_SERVER_URL` when the vite command is called `serve`
|
|
||||||
if (process.env.VITE_DEV_SERVER_URL) {
|
if (process.env.VITE_DEV_SERVER_URL) {
|
||||||
win.loadURL(process.env.VITE_DEV_SERVER_URL)
|
win.loadURL(process.env.VITE_DEV_SERVER_URL)
|
||||||
} else {
|
} else {
|
||||||
// Load your file
|
|
||||||
win.loadFile('dist/index.html');
|
win.loadFile('dist/index.html');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -199,10 +199,12 @@ export const useAppState = create<AppState>((set, get) => ({
|
|||||||
const token = localStorage.getItem('authToken');
|
const token = localStorage.getItem('authToken');
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
const user: User = await (await fetch("/api/user/profile", {
|
const response = await fetch("/api/user/profile", {
|
||||||
headers: getAuthHeaders(token)
|
headers: getAuthHeaders(token)
|
||||||
})).json();
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const user: User = await response.json();
|
||||||
restoreKeys();
|
restoreKeys();
|
||||||
|
|
||||||
set(() => ({
|
set(() => ({
|
||||||
@@ -212,6 +214,9 @@ export const useAppState = create<AppState>((set, get) => ({
|
|||||||
},
|
},
|
||||||
currentPage: "chat"
|
currentPage: "chat"
|
||||||
}));
|
}));
|
||||||
|
} else {
|
||||||
|
throw new Error("Unable to authenticate");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to restore user from localStorage:', error);
|
console.error('Failed to restore user from localStorage:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user