Clean up code and fix authentication

This commit is contained in:
2025-09-19 15:47:07 +03:00
Unverified
parent 236d3f09c8
commit 4b71eb5141
2 changed files with 16 additions and 13 deletions
-2
View File
@@ -18,11 +18,9 @@ app.whenReady().then(() => {
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) {
win.loadURL(process.env.VITE_DEV_SERVER_URL)
} else {
// Load your file
win.loadFile('dist/index.html');
}
});
+16 -11
View File
@@ -199,19 +199,24 @@ export const useAppState = create<AppState>((set, get) => ({
const token = localStorage.getItem('authToken');
if (token) {
const user: User = await (await fetch("/api/user/profile", {
const response = await fetch("/api/user/profile", {
headers: getAuthHeaders(token)
})).json();
restoreKeys();
});
set(() => ({
user: {
currentUser: user,
authToken: token
},
currentPage: "chat"
}));
if (response.ok) {
const user: User = await response.json();
restoreKeys();
set(() => ({
user: {
currentUser: user,
authToken: token
},
currentPage: "chat"
}));
} else {
throw new Error("Unable to authenticate");
}
}
} catch (error) {
console.error('Failed to restore user from localStorage:', error);