diff --git a/web/components/auth-context.tsx b/web/components/auth-context.tsx index fcc3de39..653368b6 100644 --- a/web/components/auth-context.tsx +++ b/web/components/auth-context.tsx @@ -41,6 +41,7 @@ export function AuthProvider({ children }: any) { useEffect(() => { return onIdTokenChanged(auth, async (fbUser) => { if (fbUser) { + setAuthCookies(await fbUser.getIdToken(), fbUser.refreshToken) let user = await getUser(fbUser.uid) if (!user) { const deviceToken = ensureDeviceToken() @@ -51,12 +52,11 @@ export function AuthProvider({ children }: any) { // Note: Cap on localStorage size is ~5mb localStorage.setItem(CACHED_USER_KEY, JSON.stringify(user)) setCachedReferralInfoForUser(user) - setAuthCookies(await fbUser.getIdToken(), fbUser.refreshToken) } else { // User logged out; reset to null + deleteAuthCookies() setAuthUser(null) localStorage.removeItem(CACHED_USER_KEY) - deleteAuthCookies() } }) }, [setAuthUser]) diff --git a/web/components/create-question-button.tsx b/web/components/create-question-button.tsx index 277816fa..1b8ac11e 100644 --- a/web/components/create-question-button.tsx +++ b/web/components/create-question-button.tsx @@ -1,4 +1,5 @@ import Link from 'next/link' +import { useRouter } from 'next/router' import clsx from 'clsx' import { firebaseLogin, User } from 'web/lib/firebase/users' import React from 'react' @@ -16,6 +17,7 @@ export const CreateQuestionButton = (props: { 'from-indigo-500 to-blue-500 hover:from-indigo-700 hover:to-blue-700' const { user, overrideText, className, query } = props + const router = useRouter() return (
{user ? ( @@ -26,7 +28,12 @@ export const CreateQuestionButton = (props: { ) : (