fix(auth): sign-out clears auth and redirects to /login
This commit is contained in:
parent
4ab9fd5264
commit
947f8114d2
@ -22,6 +22,7 @@ import IconUser from '@/components/icon/icon-user';
|
||||
import IconMail from '@/components/icon/icon-mail';
|
||||
import IconLockDots from '@/components/icon/icon-lock-dots';
|
||||
import IconLogout from '@/components/icon/icon-logout';
|
||||
import Cookies from 'universal-cookie';
|
||||
import IconMenuDashboard from '@/components/icon/menu/icon-menu-dashboard';
|
||||
import IconCaretDown from '@/components/icon/icon-caret-down';
|
||||
import IconMenuApps from '@/components/icon/menu/icon-menu-apps';
|
||||
@ -80,6 +81,29 @@ const Header = () => {
|
||||
router.refresh();
|
||||
};
|
||||
|
||||
const handleSignOut = () => {
|
||||
try {
|
||||
const cookies = new Cookies();
|
||||
// remove common auth cookies if present
|
||||
cookies.remove('token', { path: '/' });
|
||||
cookies.remove('auth', { path: '/' });
|
||||
cookies.remove('i18nextLng', { path: '/' });
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// remove known localStorage keys (avoid removing theme prefs)
|
||||
try {
|
||||
localStorage.removeItem('authToken');
|
||||
localStorage.removeItem('user');
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// Redirect to the login page. app/(auth)/login maps to `/login` in the URL.
|
||||
router.replace('/login');
|
||||
};
|
||||
|
||||
function createMarkup(messages: any) {
|
||||
return { __html: messages };
|
||||
}
|
||||
@ -225,10 +249,10 @@ const Header = () => {
|
||||
</Link>
|
||||
</li>
|
||||
<li className="border-t border-white-light dark:border-white-light/10">
|
||||
<Link href="/auth/boxed-signin" className="!py-3 text-danger">
|
||||
<button type="button" onClick={handleSignOut} className="!py-3 text-danger w-full text-left">
|
||||
<IconLogout className="h-4.5 w-4.5 shrink-0 rotate-90 ltr:mr-2 rtl:ml-2" />
|
||||
Sign Out
|
||||
</Link>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</Dropdown>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user