From b425d35e82efcee70bc299c709f849b8b4fd6bb7 Mon Sep 17 00:00:00 2001 From: keyan Date: Fri, 24 Sep 2021 18:04:59 -0500 Subject: [PATCH] remove use of session where inapproriate --- components/header.js | 7 ++++++- components/reply.js | 15 +++++++++------ components/upvote.js | 5 ++--- components/user-header.js | 7 +++---- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/components/header.js b/components/header.js index 403d3b72..e0bb4e4d 100644 --- a/components/header.js +++ b/components/header.js @@ -7,7 +7,7 @@ import { Button, Container, NavDropdown } from 'react-bootstrap' import Price from './price' import { useMe } from './me' import Head from 'next/head' -import { signOut, signIn } from 'next-auth/client' +import { signOut, signIn, useSession } from 'next-auth/client' import { useLightning } from './lightning' import { useEffect } from 'react' import { randInRange } from '../lib/rand' @@ -30,8 +30,13 @@ export default function Header () { const router = useRouter() const path = router.asPath.split('?')[0] const me = useMe() + const [, loading] = useSession() const Corner = () => { + if (loading && !me) { + return null + } + if (me) { return (
diff --git a/components/reply.js b/components/reply.js index 0d223434..054a1811 100644 --- a/components/reply.js +++ b/components/reply.js @@ -50,12 +50,15 @@ export default function Reply ({ parentId, onSuccess, replyOpen }) { return (
-
setReply(!reply)} - > - {reply ? 'cancel' : 'reply'} -
+ {replyOpen + ?
+ : ( +
setReply(!reply)} + > + {reply ? 'cancel' : 'reply'} +
)}
{ e.stopPropagation() if (!item) return diff --git a/components/user-header.js b/components/user-header.js index a76cd35c..38b8be49 100644 --- a/components/user-header.js +++ b/components/user-header.js @@ -1,5 +1,4 @@ import { Button } from 'react-bootstrap' -import { useSession } from 'next-auth/client' import Link from 'next/link' import { useRouter } from 'next/router' import Nav from 'react-bootstrap/Nav' @@ -9,6 +8,7 @@ import InputGroup from 'react-bootstrap/InputGroup' import * as Yup from 'yup' import { gql, useApolloClient, useMutation } from '@apollo/client' import styles from './user-header.module.css' +import { useMe } from './me' const NAME_QUERY = gql` @@ -26,7 +26,7 @@ gql` export default function UserHeader ({ user }) { const [editting, setEditting] = useState(false) - const [session] = useSession() + const me = useMe() const router = useRouter() const client = useApolloClient() const [setName] = useMutation(NAME_MUTATION) @@ -70,7 +70,6 @@ export default function UserHeader ({ user }) { throw new Error({ message: error.toString() }) } router.replace(`/${name}`) - session.user.name = name client.writeFragment({ id: `User:${user.id}`, @@ -102,7 +101,7 @@ export default function UserHeader ({ user }) { : (

@{user.name}

- {session?.user?.name === user.name && + {me?.name === user.name && }
)}