feat(auth): Implemented Session Persistence
This commit is contained in:
@@ -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"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user