From 1e8bf2433fc3de622942abf55545c27818c547cd Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Thu, 21 Jul 2022 01:32:20 -0700 Subject: [PATCH] Make sidebar logout button trigger SSR reload --- web/components/nav/sidebar.tsx | 13 ++++++++++--- web/lib/firebase/users.ts | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/web/components/nav/sidebar.tsx b/web/components/nav/sidebar.tsx index e6ce8575..581dd5fa 100644 --- a/web/components/nav/sidebar.tsx +++ b/web/components/nav/sidebar.tsx @@ -11,7 +11,7 @@ import { } from '@heroicons/react/outline' import clsx from 'clsx' import Link from 'next/link' -import { useRouter } from 'next/router' +import Router, { useRouter } from 'next/router' import { usePrivateUser, useUser } from 'web/hooks/use-user' import { firebaseLogout, User } from 'web/lib/firebase/users' import { ManifoldLogo } from './manifold-logo' @@ -31,6 +31,13 @@ import { setNotificationsAsSeen } from 'web/pages/notifications' import { PrivateUser } from 'common/user' import { useWindowSize } from 'web/hooks/use-window-size' +const logout = async () => { + // log out, and then reload the page, in case SSR wants to boot them out + // of whatever logged-in-only area of the site they might be in + await withTracking(firebaseLogout, 'sign out')() + await Router.replace(Router.asPath) +} + function getNavigation() { return [ { name: 'Home', href: '/home', icon: HomeIcon }, @@ -71,7 +78,7 @@ function getMoreNavigation(user?: User | null) { { name: 'Sign out', href: '#', - onClick: withTracking(firebaseLogout, 'sign out'), + onClick: logout, }, ] } @@ -122,7 +129,7 @@ function getMoreMobileNav() { { name: 'Sign out', href: '#', - onClick: withTracking(firebaseLogout, 'sign out'), + onClick: logout, }, ] } diff --git a/web/lib/firebase/users.ts b/web/lib/firebase/users.ts index 481f86de..4f618586 100644 --- a/web/lib/firebase/users.ts +++ b/web/lib/firebase/users.ts @@ -179,7 +179,7 @@ export async function firebaseLogin() { } export async function firebaseLogout() { - auth.signOut() + await auth.signOut() } const storage = getStorage(app)