remove use of session where inapproriate

This commit is contained in:
keyan 2021-09-24 18:04:59 -05:00
parent d4f014aef2
commit b425d35e82
4 changed files with 20 additions and 14 deletions

View File

@ -7,7 +7,7 @@ import { Button, Container, NavDropdown } from 'react-bootstrap'
import Price from './price' import Price from './price'
import { useMe } from './me' import { useMe } from './me'
import Head from 'next/head' 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 { useLightning } from './lightning'
import { useEffect } from 'react' import { useEffect } from 'react'
import { randInRange } from '../lib/rand' import { randInRange } from '../lib/rand'
@ -30,8 +30,13 @@ export default function Header () {
const router = useRouter() const router = useRouter()
const path = router.asPath.split('?')[0] const path = router.asPath.split('?')[0]
const me = useMe() const me = useMe()
const [, loading] = useSession()
const Corner = () => { const Corner = () => {
if (loading && !me) {
return null
}
if (me) { if (me) {
return ( return (
<div className='d-flex align-items-center'> <div className='d-flex align-items-center'>

View File

@ -50,12 +50,15 @@ export default function Reply ({ parentId, onSuccess, replyOpen }) {
return ( return (
<div> <div>
<div {replyOpen
className={styles.replyButtons} ? <div className={styles.replyButtons} />
onClick={() => setReply(!reply)} : (
> <div
{reply ? 'cancel' : 'reply'} className={styles.replyButtons}
</div> onClick={() => setReply(!reply)}
>
{reply ? 'cancel' : 'reply'}
</div>)}
<div className={reply ? `${styles.reply}` : 'd-none'}> <div className={reply ? `${styles.reply}` : 'd-none'}>
<Form <Form
initial={{ initial={{

View File

@ -2,7 +2,7 @@ import { LightningConsumer } from './lightning'
import UpArrow from '../svgs/lightning-arrow.svg' import UpArrow from '../svgs/lightning-arrow.svg'
import styles from './upvote.module.css' import styles from './upvote.module.css'
import { gql, useMutation } from '@apollo/client' import { gql, useMutation } from '@apollo/client'
import { signIn, useSession } from 'next-auth/client' import { signIn } from 'next-auth/client'
import { useFundError } from './fund-error' import { useFundError } from './fund-error'
import ActionTooltip from './action-tooltip' import ActionTooltip from './action-tooltip'
import { useItemAct } from './item-act' import { useItemAct } from './item-act'
@ -10,7 +10,6 @@ import Window from '../svgs/window-2-fill.svg'
import { useMe } from './me' import { useMe } from './me'
export default function UpVote ({ item, className }) { export default function UpVote ({ item, className }) {
const [session] = useSession()
const { setError } = useFundError() const { setError } = useFundError()
const { setItem } = useItemAct() const { setItem } = useItemAct()
const me = useMe() const me = useMe()
@ -97,7 +96,7 @@ export default function UpVote ({ item, className }) {
${item?.meVote ? styles.voted : ''}` ${item?.meVote ? styles.voted : ''}`
} }
onClick={ onClick={
session me
? async (e) => { ? async (e) => {
e.stopPropagation() e.stopPropagation()
if (!item) return if (!item) return

View File

@ -1,5 +1,4 @@
import { Button } from 'react-bootstrap' import { Button } from 'react-bootstrap'
import { useSession } from 'next-auth/client'
import Link from 'next/link' import Link from 'next/link'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import Nav from 'react-bootstrap/Nav' import Nav from 'react-bootstrap/Nav'
@ -9,6 +8,7 @@ import InputGroup from 'react-bootstrap/InputGroup'
import * as Yup from 'yup' import * as Yup from 'yup'
import { gql, useApolloClient, useMutation } from '@apollo/client' import { gql, useApolloClient, useMutation } from '@apollo/client'
import styles from './user-header.module.css' import styles from './user-header.module.css'
import { useMe } from './me'
const NAME_QUERY = const NAME_QUERY =
gql` gql`
@ -26,7 +26,7 @@ gql`
export default function UserHeader ({ user }) { export default function UserHeader ({ user }) {
const [editting, setEditting] = useState(false) const [editting, setEditting] = useState(false)
const [session] = useSession() const me = useMe()
const router = useRouter() const router = useRouter()
const client = useApolloClient() const client = useApolloClient()
const [setName] = useMutation(NAME_MUTATION) const [setName] = useMutation(NAME_MUTATION)
@ -70,7 +70,6 @@ export default function UserHeader ({ user }) {
throw new Error({ message: error.toString() }) throw new Error({ message: error.toString() })
} }
router.replace(`/${name}`) router.replace(`/${name}`)
session.user.name = name
client.writeFragment({ client.writeFragment({
id: `User:${user.id}`, id: `User:${user.id}`,
@ -102,7 +101,7 @@ export default function UserHeader ({ user }) {
: ( : (
<div className='d-flex align-items-center'> <div className='d-flex align-items-center'>
<h2 className='mb-0'>@{user.name}</h2> <h2 className='mb-0'>@{user.name}</h2>
{session?.user?.name === user.name && {me?.name === user.name &&
<Button variant='link' onClick={() => setEditting(true)}>edit nym</Button>} <Button variant='link' onClick={() => setEditting(true)}>edit nym</Button>}
</div> </div>
)} )}