generated from fahricansecer/boilerplate-fe
This commit is contained in:
@@ -23,6 +23,7 @@ import { useState } from "react";
|
||||
import { MdMail } from "react-icons/md";
|
||||
import { BiLock } from "react-icons/bi";
|
||||
import { Link } from "@/i18n/navigation";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
const schema = yup.object({
|
||||
email: yup.string().email().required(),
|
||||
@@ -39,6 +40,7 @@ interface LoginModalProps {
|
||||
export function LoginModal({ open, onOpenChange }: LoginModalProps) {
|
||||
const t = useTranslations();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
@@ -62,6 +64,7 @@ export function LoginModal({ open, onOpenChange }: LoginModalProps) {
|
||||
throw new Error(res.error);
|
||||
}
|
||||
|
||||
queryClient.clear();
|
||||
onOpenChange(false);
|
||||
toaster.success({
|
||||
title: t("auth.login-success") || "Login successful!",
|
||||
|
||||
@@ -38,6 +38,7 @@ import { signOut, useSession } from "next-auth/react";
|
||||
import { authConfig } from "@/config/auth";
|
||||
import { LoginModal } from "@/components/auth/login-modal";
|
||||
import { LuLogIn } from "react-icons/lu";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
export default function Header() {
|
||||
const t = useTranslations();
|
||||
@@ -45,6 +46,7 @@ export default function Header() {
|
||||
const [loginModalOpen, setLoginModalOpen] = useState(false);
|
||||
const router = useRouter();
|
||||
const { data: session, status } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const isAuthenticated = !!session;
|
||||
const isLoading = status === "loading";
|
||||
@@ -61,6 +63,7 @@ export default function Header() {
|
||||
}, []);
|
||||
|
||||
const handleLogout = async () => {
|
||||
queryClient.clear();
|
||||
await signOut({ redirect: false });
|
||||
if (authConfig.isAuthRequired) {
|
||||
router.replace("/signin");
|
||||
|
||||
Reference in New Issue
Block a user