feat: redirect to login page

This commit is contained in:
Junseo Park 2021-02-27 15:01:48 +09:00
parent 163670a0a2
commit 623ebcf8eb
2 changed files with 23 additions and 9 deletions

View File

@ -1,28 +1,35 @@
import { NextPage, NextPageContext } from 'next'
import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { Form, Formik } from 'formik'
import useCopyClipboard from 'react-use-clipboard'
import { get } from '@utils/Query'
import { parseCookie } from '@utils/Tools'
import { DeveloperBotSchema } from '@utils/Yup'
import { parseCookie, redirectTo } from '@utils/Tools'
import { ParsedUrlQuery } from 'querystring'
import { Bot, BotSpec, User } from '@types'
import { Bot, BotSpec } from '@types'
import NotFound from 'pages/404'
import { Form, Formik } from 'formik'
import { DeveloperBotSchema } from '@utils/Yup'
const Button = dynamic(() => import('@components/Button'))
const Input = dynamic(() => import('@components/Form/Input'))
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
const BotApplication: NextPage<BotApplicationProps> = ({ spec, bot }) => {
const BotApplication: NextPage<BotApplicationProps> = ({ user, spec, bot }) => {
const router = useRouter()
const [ showToken, setShowToken ] = useState(false)
const [ tokenCopied, setTokenCopied ] = useCopyClipboard(spec?.token, {
successDuration: 1000
})
if(!user) {
localStorage.redirectTo = window.location.href
redirectTo(router, 'login')
return
}
if(!bot || !spec) return <NotFound />
return <DeveloperLayout enabled='applications'>
<h1 className='text-3xl font-bold'> </h1>
@ -65,7 +72,7 @@ const BotApplication: NextPage<BotApplicationProps> = ({ spec, bot }) => {
}
interface BotApplicationProps {
user: User
user: string
spec: BotSpec
bot: Bot
}
@ -75,7 +82,7 @@ export const getServerSideProps = async (ctx: Context) => {
const user = await get.Authorization(parsed?.token) || ''
return {
props: { spec: await get.botSpec(ctx.query.id, user), bot: await get.bot.load(ctx.query.id) }
props: { user, spec: await get.botSpec(ctx.query.id, user), bot: await get.bot.load(ctx.query.id) }
}
}

View File

@ -1,8 +1,9 @@
import { NextPage, NextPageContext } from 'next'
import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'
import { get } from '@utils/Query'
import { parseCookie } from '@utils/Tools'
import { parseCookie, redirectTo } from '@utils/Tools'
import { Bot, User } from '@types'
@ -10,6 +11,12 @@ const Application = dynamic(() => import('@components/Application'))
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
const Applications: NextPage<ApplicationsProps> = ({ user }) => {
const router = useRouter()
if(!user) {
localStorage.redirectTo = window.location.href
redirectTo(router, 'login')
return
}
return <DeveloperLayout enabled='applications'>
<h1 className='text-3xl font-bold'> </h1>
<p className='text-gray-400'> API를 .</p>