Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Don't show delete and create buttons to unauthorized users (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Helen Tera committed Nov 7, 2021
1 parent f03a612 commit 9791259
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import Head from 'next/head'
import Link from 'next/link'
import React from 'react'
import { useTheorems } from '../lib/data'
import { useSession } from 'next-auth/react'


export default function IndexPage() {
const theorems = useTheorems()
const session = useSession({ required: false })

return (
<>
Expand All @@ -21,7 +23,8 @@ export default function IndexPage() {
<h1 className="font-semibold text-2xl">Theorems</h1>
<p className="mb-4">Here you can find the list of all theorems currently in the system.</p>
</div>
<Link href={'/create'}><a className="btn">Create Theorem</a></Link>
{session.status === 'authenticated' &&
<Link href={'/create'}><a className="btn">Create Theorem</a></Link>}
</div>
<div className="flex">
<ol className="w-full">
Expand Down
5 changes: 4 additions & 1 deletion pages/theorem/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import React from 'react'
import { useRouter } from 'next/router'
import { useSession } from 'next-auth/react'

import { deleteTheorem, useTheorem } from '../../lib/data'
import Head from 'next/head'
Expand All @@ -9,6 +10,7 @@ import Theorem from '../../components/Theorem'
export default function ProofPage() {
const router = useRouter()
const theorem = useTheorem(router.query.id)
const session = useSession({ required: false })

if (!theorem) return null

Expand All @@ -32,7 +34,8 @@ export default function ProofPage() {

<Theorem theorem={theorem} />

<button className="btn btn-secondary block ml-auto" onClick={onClickDelete}>Delete Theorem</button>
{session.status === 'authenticated' &&
<button className="btn btn-secondary block ml-auto" onClick={onClickDelete}>Delete Theorem</button>}
</>
)
}

0 comments on commit 9791259

Please sign in to comment.