tldraw/pages/room/[id].tsx

36 lines
884 B
TypeScript
Raw Normal View History

2021-06-28 20:45:06 +00:00
import dynamic from 'next/dynamic'
import { GetServerSideProps } from 'next'
import { getSession } from 'next-auth/client'
2021-06-30 20:31:29 +00:00
import { useEffect } from 'react'
import coopState from 'state/coop/coop-state'
2021-06-28 20:45:06 +00:00
const Editor = dynamic(() => import('components/editor'), { ssr: false })
export default function Room({ id }: { id: string }): JSX.Element {
2021-06-30 20:31:29 +00:00
useEffect(() => {
2021-07-07 13:02:48 +00:00
coopState.send('JOINED_ROOM', { id })
2021-06-30 20:31:29 +00:00
return () => {
coopState.send('LEFT_ROOM')
}
}, [])
2021-06-28 20:45:06 +00:00
return <Editor roomId={id} />
}
export const getServerSideProps: GetServerSideProps = async (context) => {
const session = await getSession(context)
const { id } = context.query
2021-07-07 14:42:17 +00:00
if (!session?.user && process.env.NODE_ENV !== 'development') {
2021-07-07 13:02:48 +00:00
context.res.setHeader('Location', `/sponsorware`)
context.res.statusCode = 307
}
2021-06-28 20:45:06 +00:00
return {
props: {
session,
id,
},
}
}