mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
feat(api): blocking unverified user
This commit is contained in:
parent
86621cc4a5
commit
306d9118a9
@ -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',
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -130,6 +130,7 @@ export interface TokenRegister {
|
||||
email: string
|
||||
username: string
|
||||
discriminator: string
|
||||
verified: boolean
|
||||
}
|
||||
|
||||
export interface DiscordUserInfo {
|
||||
|
||||
@ -324,9 +324,10 @@ async function getDiscordUser(id: string):Promise<DiscordUser> {
|
||||
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<string> {
|
||||
async function assignToken(info: TokenRegister):Promise<string|null> {
|
||||
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 }) })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user