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"
|
||||
})
|
||||
|
||||
// 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');
|
||||
}
|
||||
});
|
||||
+15
-10
@@ -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();
|
||||
if (response.ok) {
|
||||
const user: User = await response.json();
|
||||
restoreKeys();
|
||||
|
||||
set(() => ({
|
||||
user: {
|
||||
currentUser: user,
|
||||
authToken: token
|
||||
},
|
||||
currentPage: "chat"
|
||||
}));
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user