mirror of
https://github.com/koreanbots/core.git
synced 2025-12-17 06:40:24 +00:00
feat: redirect to login page
This commit is contained in:
parent
163670a0a2
commit
623ebcf8eb
@ -1,28 +1,35 @@
|
|||||||
import { NextPage, NextPageContext } from 'next'
|
import { NextPage, NextPageContext } from 'next'
|
||||||
import dynamic from 'next/dynamic'
|
import dynamic from 'next/dynamic'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
import { Form, Formik } from 'formik'
|
||||||
import useCopyClipboard from 'react-use-clipboard'
|
import useCopyClipboard from 'react-use-clipboard'
|
||||||
|
|
||||||
import { get } from '@utils/Query'
|
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 { ParsedUrlQuery } from 'querystring'
|
||||||
import { Bot, BotSpec, User } from '@types'
|
import { Bot, BotSpec } from '@types'
|
||||||
|
|
||||||
import NotFound from 'pages/404'
|
import NotFound from 'pages/404'
|
||||||
import { Form, Formik } from 'formik'
|
|
||||||
import { DeveloperBotSchema } from '@utils/Yup'
|
|
||||||
|
|
||||||
const Button = dynamic(() => import('@components/Button'))
|
const Button = dynamic(() => import('@components/Button'))
|
||||||
const Input = dynamic(() => import('@components/Form/Input'))
|
const Input = dynamic(() => import('@components/Form/Input'))
|
||||||
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
|
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
|
||||||
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
|
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 [ showToken, setShowToken ] = useState(false)
|
||||||
const [ tokenCopied, setTokenCopied ] = useCopyClipboard(spec?.token, {
|
const [ tokenCopied, setTokenCopied ] = useCopyClipboard(spec?.token, {
|
||||||
successDuration: 1000
|
successDuration: 1000
|
||||||
})
|
})
|
||||||
|
if(!user) {
|
||||||
|
localStorage.redirectTo = window.location.href
|
||||||
|
redirectTo(router, 'login')
|
||||||
|
return
|
||||||
|
}
|
||||||
if(!bot || !spec) return <NotFound />
|
if(!bot || !spec) return <NotFound />
|
||||||
return <DeveloperLayout enabled='applications'>
|
return <DeveloperLayout enabled='applications'>
|
||||||
<h1 className='text-3xl font-bold'>봇 설정</h1>
|
<h1 className='text-3xl font-bold'>봇 설정</h1>
|
||||||
@ -65,7 +72,7 @@ const BotApplication: NextPage<BotApplicationProps> = ({ spec, bot }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface BotApplicationProps {
|
interface BotApplicationProps {
|
||||||
user: User
|
user: string
|
||||||
spec: BotSpec
|
spec: BotSpec
|
||||||
bot: Bot
|
bot: Bot
|
||||||
}
|
}
|
||||||
@ -75,7 +82,7 @@ export const getServerSideProps = async (ctx: Context) => {
|
|||||||
const user = await get.Authorization(parsed?.token) || ''
|
const user = await get.Authorization(parsed?.token) || ''
|
||||||
|
|
||||||
return {
|
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) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import { NextPage, NextPageContext } from 'next'
|
import { NextPage, NextPageContext } from 'next'
|
||||||
import dynamic from 'next/dynamic'
|
import dynamic from 'next/dynamic'
|
||||||
|
import { useRouter } from 'next/router'
|
||||||
|
|
||||||
import { get } from '@utils/Query'
|
import { get } from '@utils/Query'
|
||||||
import { parseCookie } from '@utils/Tools'
|
import { parseCookie, redirectTo } from '@utils/Tools'
|
||||||
|
|
||||||
import { Bot, User } from '@types'
|
import { Bot, User } from '@types'
|
||||||
|
|
||||||
@ -10,6 +11,12 @@ const Application = dynamic(() => import('@components/Application'))
|
|||||||
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
|
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
|
||||||
|
|
||||||
const Applications: NextPage<ApplicationsProps> = ({ user }) => {
|
const Applications: NextPage<ApplicationsProps> = ({ user }) => {
|
||||||
|
const router = useRouter()
|
||||||
|
if(!user) {
|
||||||
|
localStorage.redirectTo = window.location.href
|
||||||
|
redirectTo(router, 'login')
|
||||||
|
return
|
||||||
|
}
|
||||||
return <DeveloperLayout enabled='applications'>
|
return <DeveloperLayout enabled='applications'>
|
||||||
<h1 className='text-3xl font-bold'>나의 봇</h1>
|
<h1 className='text-3xl font-bold'>나의 봇</h1>
|
||||||
<p className='text-gray-400'>한국 디스코드봇 리스트 API를 활용하여 봇에 다양한 기능을 추가해보세요.</p>
|
<p className='text-gray-400'>한국 디스코드봇 리스트 API를 활용하여 봇에 다양한 기능을 추가해보세요.</p>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user