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