logout
This commit is contained in:
@@ -157,6 +157,7 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
|
||||
<LogoutPrompt
|
||||
visible={logoutModal}
|
||||
onClick={toggleLogoutModal}
|
||||
slug={name as string}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import Prompt, { PromptProps } from '@/components/utils/Prompt'
|
||||
import { useAuthStore } from '@/zustand/authStore';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { removeToken, removeRefreshToken } from '@/lib/api/func';
|
||||
@@ -16,24 +15,20 @@ function LogoutPrompt({ slug, ...rest }: LogoutPromptProps) {
|
||||
keyPrefix: 'LogoutModal'
|
||||
});
|
||||
const authLogout = useAuthStore((state) => state.logout);
|
||||
const router = useRouter();
|
||||
const userIsAuthenticated = useAuthStore((state) => state.isAuthenticated);
|
||||
|
||||
const onConfirmLogout = async (e: React.MouseEvent) => {
|
||||
if (!e) return;
|
||||
if (userIsAuthenticated) {
|
||||
authLogout();
|
||||
await removeToken();
|
||||
await removeRefreshToken();
|
||||
}
|
||||
rest.onClick?.(e);
|
||||
authLogout();
|
||||
await removeToken();
|
||||
await removeRefreshToken();
|
||||
const redirectPath = slug ? `/${slug}` : '/';
|
||||
router.replace(redirectPath);
|
||||
window.location.href = redirectPath;
|
||||
};
|
||||
|
||||
const toggleShareModalVisiblity = (e: React.MouseEvent) => {
|
||||
const toggleLogoutModalVisibility = (e: React.MouseEvent) => {
|
||||
e?.preventDefault();
|
||||
e?.stopPropagation();
|
||||
console.log(e);
|
||||
rest.onClick?.(e);
|
||||
};
|
||||
|
||||
@@ -45,7 +40,7 @@ function LogoutPrompt({ slug, ...rest }: LogoutPromptProps) {
|
||||
textConfirm={t("ButtonOk")}
|
||||
textCancel={t("ButtonCancel")}
|
||||
onConfirm={onConfirmLogout}
|
||||
onCancel={toggleShareModalVisiblity}
|
||||
onCancel={toggleLogoutModalVisibility}
|
||||
{...rest}>
|
||||
<></>
|
||||
</Prompt>
|
||||
|
||||
Reference in New Issue
Block a user