logout error
This commit is contained in:
parent
6783fba264
commit
ec383c109f
|
|
@ -5,16 +5,17 @@ import { getToken } from '../utils/tokenHelper.js';
|
|||
const TOKEN_KEY = 'auth_token';
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
// --- Request Interceptor ---
|
||||
api.interceptors.request.use(
|
||||
async (config: AxiosRequestConfig) : Promise<any> => {
|
||||
async (config: AxiosRequestConfig): Promise<any> => {
|
||||
const token = await getToken(TOKEN_KEY);
|
||||
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}`);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import { ipcMain } from 'electron';
|
||||
import { getToken, saveToken, clearToken } from '../utils/tokenHelper.js';
|
||||
import { handleLogin, takeScreenshot } from '../utils/utilityFunctions.js';
|
||||
import api from '../api/axiosClient.js';
|
||||
|
||||
ipcMain.handle('get-token', async (_, TOKEN_KEY: string) => {
|
||||
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 }) => {
|
||||
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'),
|
||||
sendFrameAction: (payload) => ipcSend('sendFrameAction', payload),
|
||||
|
||||
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),
|
||||
uploadScreenshot: () => ipcRenderer.invoke('upload-screenshot'),
|
||||
} satisfies Window['electron']);
|
||||
|
|
|
|||
|
|
@ -100,9 +100,20 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
|||
return () => window.removeEventListener("resize", handleResize);
|
||||
}, []);
|
||||
|
||||
const handleLogout = () => {
|
||||
const handleLogout = async () => {
|
||||
localStorage.removeItem("user");
|
||||
setUser(null);
|
||||
|
||||
console.log("calling Logout UI")
|
||||
|
||||
|
||||
try {
|
||||
const res = await window.electron.logout()
|
||||
console.log(res)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
navigate("/login");
|
||||
};
|
||||
|
||||
|
|
@ -240,7 +251,7 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
|||
setIsPaused(false);
|
||||
setEndTime(new Date());
|
||||
|
||||
console.log("projectTrackingMap",projectTrackingMap)
|
||||
console.log("projectTrackingMap", projectTrackingMap)
|
||||
};
|
||||
|
||||
// Cleanup timer on unmount
|
||||
|
|
@ -302,8 +313,7 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
|||
className={`
|
||||
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
|
||||
${
|
||||
isMobile
|
||||
${isMobile
|
||||
? isSidebarOpen
|
||||
? "translate-x-0 w-64"
|
||||
: "-translate-x-full w-64"
|
||||
|
|
@ -339,8 +349,7 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
|||
to={item.path}
|
||||
end={item.exact}
|
||||
className={({ isActive }) =>
|
||||
`flex items-center gap-3 my-1 font-medium transition-all duration-150 ${
|
||||
isActive
|
||||
`flex items-center gap-3 my-1 font-medium transition-all duration-150 ${isActive
|
||||
? "bg-primary text-primary-content rounded-lg"
|
||||
: "hover:bg-base-300 rounded-lg"
|
||||
}`
|
||||
|
|
@ -418,7 +427,7 @@ const DashboardLayout: React.FC<DashboardLayoutProps> = ({ setUser }) => {
|
|||
|
||||
{/* Page Content */}
|
||||
<main className="flex-1 overflow-y-auto p-4 md:px-6 no-scrollbar">
|
||||
<Outlet context={trackingState}/>
|
||||
<Outlet context={trackingState} />
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ interface Window {
|
|||
) => UnsubscribeFunction;
|
||||
sendFrameAction: (payload: FrameWindowAction) => void;
|
||||
login: (credentials: { email: string; password: string }) => Promise<any>;
|
||||
logout: () => {};
|
||||
getToken: (tokenKey: string) => Promise<string | null>;
|
||||
uploadScreenshot: () => {};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue