Make sidebar login button trigger SSR reload
This commit is contained in:
parent
1e8bf2433f
commit
1d4524774b
|
@ -1,4 +1,5 @@
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { firebaseLogin, User } from 'web/lib/firebase/users'
|
import { firebaseLogin, User } from 'web/lib/firebase/users'
|
||||||
import React from 'react'
|
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'
|
'from-indigo-500 to-blue-500 hover:from-indigo-700 hover:to-blue-700'
|
||||||
|
|
||||||
const { user, overrideText, className, query } = props
|
const { user, overrideText, className, query } = props
|
||||||
|
const router = useRouter()
|
||||||
return (
|
return (
|
||||||
<div className={clsx('flex justify-center', className)}>
|
<div className={clsx('flex justify-center', className)}>
|
||||||
{user ? (
|
{user ? (
|
||||||
|
@ -26,7 +28,12 @@ export const CreateQuestionButton = (props: {
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
onClick={firebaseLogin}
|
onClick={async () => {
|
||||||
|
// login, and then reload the page, to hit any SSR redirect (e.g.
|
||||||
|
// redirecting from / to /home for logged in users)
|
||||||
|
await firebaseLogin()
|
||||||
|
router.replace(router.asPath)
|
||||||
|
}}
|
||||||
className={clsx(gradient, createButtonStyle)}
|
className={clsx(gradient, createButtonStyle)}
|
||||||
>
|
>
|
||||||
Sign in
|
Sign in
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
import React, { useEffect } from 'react'
|
|
||||||
import { useRouter } from 'next/router'
|
|
||||||
import { useUser } from 'web/hooks/use-user'
|
|
||||||
import { Contract, getContractsBySlugs } from 'web/lib/firebase/contracts'
|
import { Contract, getContractsBySlugs } from 'web/lib/firebase/contracts'
|
||||||
import { Page } from 'web/components/page'
|
import { Page } from 'web/components/page'
|
||||||
import { LandingPagePanel } from 'web/components/landing-page-panel'
|
import { LandingPagePanel } from 'web/components/landing-page-panel'
|
||||||
|
@ -29,19 +26,8 @@ export const getServerSideProps = redirectIfLoggedIn('/home', async (_) => {
|
||||||
export default function Home(props: { hotContracts: Contract[] }) {
|
export default function Home(props: { hotContracts: Contract[] }) {
|
||||||
const { hotContracts } = props
|
const { hotContracts } = props
|
||||||
|
|
||||||
// for now this redirect in the component is how we handle the case where they are
|
|
||||||
// on this page and they log in -- in the future we will make some cleaner way
|
|
||||||
const user = useUser()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
useSaveReferral()
|
useSaveReferral()
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (user != null) {
|
|
||||||
router.replace('/home')
|
|
||||||
}
|
|
||||||
}, [router, user])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<div className="px-4 pt-2 md:mt-0 lg:hidden">
|
<div className="px-4 pt-2 md:mt-0 lg:hidden">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user