diff --git a/pages/api/auth/discord/callback.ts b/pages/api/auth/discord/callback.ts index 218eaec..7382e72 100644 --- a/pages/api/auth/discord/callback.ts +++ b/pages/api/auth/discord/callback.ts @@ -53,7 +53,10 @@ const Callback = RequestHandler().get(async (req: ApiRequest, res) => { email: user.email, username: user.username, discriminator: user.discriminator, + verified: user.verified }) + + if(!userToken) return res.redirect(301, 'https://docs.koreanbots.dev/bots/account/unverified') const info = verify(userToken) res.setHeader( 'set-cookie', diff --git a/pages/callback/discord.tsx b/pages/callback/discord.tsx index e8d19f4..0d44875 100644 --- a/pages/callback/discord.tsx +++ b/pages/callback/discord.tsx @@ -1,4 +1,4 @@ -import { NextPage} from 'next' +import { NextPage } from 'next' import dynamic from 'next/dynamic' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' diff --git a/types/index.ts b/types/index.ts index 5d7d1dc..bd1314b 100644 --- a/types/index.ts +++ b/types/index.ts @@ -130,6 +130,7 @@ export interface TokenRegister { email: string username: string discriminator: string + verified: boolean } export interface DiscordUserInfo { diff --git a/utils/Query.ts b/utils/Query.ts index 1ac3b0f..9d0b5cf 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -324,9 +324,10 @@ async function getDiscordUser(id: string):Promise { return DiscordBot.users.cache.get(id) ?? await DiscordBot.users.fetch(id, false, true).then(u => u.toJSON()).catch(()=>null) } -async function assignToken(info: TokenRegister):Promise { +async function assignToken(info: TokenRegister):Promise { let token = await knex('users').select(['token']).where({ id: info.id }) let t: string + if(!info.verified) return null if(token.length === 0) { t = sign({ id: info.id }, { expiresIn: '30d' }) await knex('users').insert({ token: t, date: Math.round(Number(new Date()) / 1000), id: info.id, email: info.email, tag: info.discriminator, username: info.username, discord: sign({ access_token: info.access_token, expires_in: info.expires_in, refresh_token: info.refresh_token }) })