feat(auth): Implemented Session Persistence

This commit is contained in:
dhinesh-m24
2026-01-29 12:39:45 +05:30
parent e214e32c17
commit 7133e59e57
10 changed files with 417 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { Link, useLocation } from 'react-router-dom';
import { Link, useLocation, useNavigate } from 'react-router-dom';
import { LogOut, Menu, X } from 'lucide-react';
import { Button } from '../../common/components/ui/button';
import { NAV_CONFIG } from "../../common/config/navigation";
@@ -22,6 +22,19 @@ const Sidebar: React.FC<SidebarProps> = ({
onLogout
}) => {
const location = useLocation();
const navigate = useNavigate();
/**
* Handle logout with navigation
* Ensures user is redirected to login page after logout
*/
const handleLogoutClick = async () => {
onLogout();
// Small delay to allow logout to complete before navigation
setTimeout(() => {
navigate('/login', { replace: true });
}, 100);
};
// Filter navigation based on user role
const filteredNav = useMemo(() => {
@@ -107,7 +120,7 @@ const Sidebar: React.FC<SidebarProps> = ({
<Button
variant="ghost"
size="icon"
onClick={onLogout}
onClick={handleLogoutClick}
title="Logout"
className="text-secondary-text hover:text-destructive hover:bg-destructive/10"
>