From d08979b09a33510475905a09599f2ead60847baf Mon Sep 17 00:00:00 2001 From: Harshpreet Singh Johar Date: Wed, 31 Jan 2024 10:32:34 +0530 Subject: [PATCH] Fixed Logout is buggy #159 --- lib/logout.ts | 4 +++- pages/api/auth/[...nextauth].ts | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/logout.ts b/lib/logout.ts index 8afc31c72..4c5037720 100644 --- a/lib/logout.ts +++ b/lib/logout.ts @@ -2,6 +2,7 @@ import Cookies from "universal-cookie"; import { signOut } from "next-auth/react"; import { NextRouter } from "next/router"; import { Session } from "next-auth"; +import { Common } from "../constants/common"; const logout = async (router: NextRouter, session: Session | null) => { try { @@ -10,12 +11,13 @@ const logout = async (router: NextRouter, session: Session | null) => { let data; if (session) { data = session; - signOut(); + await signOut(); } else { data = cookies.get("session-token"); } cookies.remove("redirectPath"); cookies.remove("session-token"); + localStorage.removeItem(Common.AUTHORIZATION); router.push('/'); return { diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 26d737c1b..010e2ea16 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -21,7 +21,6 @@ const authOptions = (req: NextApiRequest, res: NextApiResponse) => { url: "/v1/users", token: cookies.get("session-token").token, }); - console.log(backendRes); return session; },