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