Fix build and redirect logged out users from '/create' to '/'

This commit is contained in:
jahooma 2021-12-15 21:58:28 -06:00
parent f2d19360aa
commit b9fb1d0f31

View File

@ -1,5 +1,5 @@
import router from 'next/router' import router from 'next/router'
import { useState } from 'react' import { useEffect, useState } from 'react'
import { ContractsList } from '../components/contracts-list' import { ContractsList } from '../components/contracts-list'
import { Header } from '../components/header' import { Header } from '../components/header'
@ -12,6 +12,10 @@ import { createContract } from '../lib/service/create-contract'
export default function NewContract() { export default function NewContract() {
const creator = useUser() const creator = useUser()
useEffect(() => {
if (!creator) router.push('/')
})
const [initialProb, setInitialProb] = useState(50) const [initialProb, setInitialProb] = useState(50)
const [question, setQuestion] = useState('') const [question, setQuestion] = useState('')
const [description, setDescription] = useState('') const [description, setDescription] = useState('')
@ -34,6 +38,8 @@ export default function NewContract() {
const descriptionPlaceholder = `e.g. This market will resolve to “Yes” if, by June 2, 2021, 11:59:59 PM ET, Paxlovid (also known under PF-07321332)...` const descriptionPlaceholder = `e.g. This market will resolve to “Yes” if, by June 2, 2021, 11:59:59 PM ET, Paxlovid (also known under PF-07321332)...`
if (!creator) return <></>
return ( return (
<div> <div>
<Header /> <Header />