logout error
This commit is contained in:
parent
6783fba264
commit
ec383c109f
|
|
@ -5,7 +5,7 @@ import { getToken } from '../utils/tokenHelper.js';
|
||||||
const TOKEN_KEY = 'auth_token';
|
const TOKEN_KEY = 'auth_token';
|
||||||
|
|
||||||
const api: AxiosInstance = axios.create({
|
const api: AxiosInstance = axios.create({
|
||||||
baseURL: 'https://api.example.com', // 🔁 your backend
|
baseURL: 'https://wired-terminally-muskrat.ngrok-free.app/api/v1', // 🔁 your backend
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -14,7 +14,8 @@ api.interceptors.request.use(
|
||||||
async (config: AxiosRequestConfig): Promise<any> => {
|
async (config: AxiosRequestConfig): Promise<any> => {
|
||||||
const token = await getToken(TOKEN_KEY);
|
const token = await getToken(TOKEN_KEY);
|
||||||
if (token && config.headers) {
|
if (token && config.headers) {
|
||||||
config.headers.Authorization = `Bearer ${token}`;
|
config.headers.token = token;
|
||||||
|
config.headers['ngrok-skip-browser-warning'] = 98098;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[Axios] ${config.method?.toUpperCase()} ${config.url}`);
|
console.log(`[Axios] ${config.method?.toUpperCase()} ${config.url}`);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
import { ipcMain } from 'electron';
|
import { ipcMain } from 'electron';
|
||||||
import { getToken, saveToken, clearToken } from '../utils/tokenHelper.js';
|
import { getToken, saveToken, clearToken } from '../utils/tokenHelper.js';
|
||||||
import { handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
|
import { handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
|
||||||
|
import api from '../api/axiosClient.js';
|
||||||
|
|
||||||
ipcMain.handle('get-token', async (_, TOKEN_KEY: string) => {
|
ipcMain.handle('get-token', async (_, TOKEN_KEY: string) => {
|
||||||
return await getToken(TOKEN_KEY);
|
return await getToken(TOKEN_KEY);
|
||||||
|
|
@ -26,3 +27,10 @@ ipcMain.handle('upload-screenshot', async () => {
|
||||||
ipcMain.handle('login-request', async (event, credentials: { email: string, password: string }) => {
|
ipcMain.handle('login-request', async (event, credentials: { email: string, password: string }) => {
|
||||||
return handleLogin(credentials);
|
return handleLogin(credentials);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('logout-request', async () => {
|
||||||
|
(async () => {
|
||||||
|
console.log("Handle Logout listened")
|
||||||
|
await api.get("/logout");
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
|
@ -16,7 +16,11 @@ contextBridge.exposeInMainWorld('electron', {
|
||||||
}),
|
}),
|
||||||
getStaticData: () => ipcInvoke('getStaticData'),
|
getStaticData: () => ipcInvoke('getStaticData'),
|
||||||
sendFrameAction: (payload) => ipcSend('sendFrameAction', payload),
|
sendFrameAction: (payload) => ipcSend('sendFrameAction', payload),
|
||||||
|
|
||||||
login: (credentials: { email: string, password: string }) => ipcRenderer.invoke('login-request', credentials),
|
login: (credentials: { email: string, password: string }) => ipcRenderer.invoke('login-request', credentials),
|
||||||
|
|
||||||
|
logout: () => ipcRenderer.invoke('logout-request'),
|
||||||
|
|
||||||
getToken: (TOKEN_KEY: string) => ipcRenderer.invoke('get-token', TOKEN_KEY),
|
getToken: (TOKEN_KEY: string) => ipcRenderer.invoke('get-token', TOKEN_KEY),
|
||||||
uploadScreenshot: () => ipcRenderer.invoke('upload-screenshot'),
|
uploadScreenshot: () => ipcRenderer.invoke('upload-screenshot'),
|
||||||
} satisfies Window['electron']);
|
} satisfies Window['electron']);
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,20 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
||||||
return () => window.removeEventListener("resize", handleResize);
|
return () => window.removeEventListener("resize", handleResize);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = async () => {
|
||||||
localStorage.removeItem("user");
|
localStorage.removeItem("user");
|
||||||
setUser(null);
|
setUser(null);
|
||||||
|
|
||||||
|
console.log("calling Logout UI")
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await window.electron.logout()
|
||||||
|
console.log(res)
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -302,8 +313,7 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
||||||
className={`
|
className={`
|
||||||
fixed md:relative inset-y-0 left-0 z-40 transform
|
fixed md:relative inset-y-0 left-0 z-40 transform
|
||||||
bg-base-100 border-r border-t border-base-300 transition-all duration-300 ease-in-out
|
bg-base-100 border-r border-t border-base-300 transition-all duration-300 ease-in-out
|
||||||
${
|
${isMobile
|
||||||
isMobile
|
|
||||||
? isSidebarOpen
|
? isSidebarOpen
|
||||||
? "translate-x-0 w-64"
|
? "translate-x-0 w-64"
|
||||||
: "-translate-x-full w-64"
|
: "-translate-x-full w-64"
|
||||||
|
|
@ -339,8 +349,7 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
||||||
to={item.path}
|
to={item.path}
|
||||||
end={item.exact}
|
end={item.exact}
|
||||||
className={({ isActive }) =>
|
className={({ isActive }) =>
|
||||||
`flex items-center gap-3 my-1 font-medium transition-all duration-150 ${
|
`flex items-center gap-3 my-1 font-medium transition-all duration-150 ${isActive
|
||||||
isActive
|
|
||||||
? "bg-primary text-primary-content rounded-lg"
|
? "bg-primary text-primary-content rounded-lg"
|
||||||
: "hover:bg-base-300 rounded-lg"
|
: "hover:bg-base-300 rounded-lg"
|
||||||
}`
|
}`
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ interface Window {
|
||||||
) => UnsubscribeFunction;
|
) => UnsubscribeFunction;
|
||||||
sendFrameAction: (payload: FrameWindowAction) => void;
|
sendFrameAction: (payload: FrameWindowAction) => void;
|
||||||
login: (credentials: { email: string; password: string }) => Promise<any>;
|
login: (credentials: { email: string; password: string }) => Promise<any>;
|
||||||
|
logout: () => {};
|
||||||
getToken: (tokenKey: string) => Promise<string | null>;
|
getToken: (tokenKey: string) => Promise<string | null>;
|
||||||
uploadScreenshot: () => {};
|
uploadScreenshot: () => {};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue