From d32938e1faa2e7dba9f9d5ad29d433c94f56d04b Mon Sep 17 00:00:00 2001 From: Cr4yfish <58395553+cr4yfish@users.noreply.github.com> Date: Sun, 9 Jul 2023 00:23:26 +0200 Subject: [PATCH] Added logout helper --- utils/authFunctions.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 utils/authFunctions.ts diff --git a/utils/authFunctions.ts b/utils/authFunctions.ts new file mode 100644 index 0000000..d24cc7a --- /dev/null +++ b/utils/authFunctions.ts @@ -0,0 +1,17 @@ +import { deleteCookie } from "cookies-next"; +import { GetSiteResponse } from "lemmy-js-client"; + +export const handleLogout = async ({ session, setSession, router } : { session: any, setSession: Function, router: any }) => { + + // delete the cookie + deleteCookie("jwt"); + + // delete sessionStorage + sessionStorage.removeItem("jwt"); + + // set session to empty + setSession({ ...session, user: {} as GetSiteResponse, jwt: "" }); + + // redirect to home + router.push("/"); +} \ No newline at end of file