fix: prevent perm missing

This commit is contained in:
wonderlandpark 2021-06-04 08:58:35 +09:00
parent d1944b0ce4
commit 14490e22ac

View File

@ -334,7 +334,7 @@ async function getDiscordUser(id: string):Promise<DiscordUser> {
* @returns 2 - Blocked
*/
async function assignToken(info: TokenRegister):Promise<string|1|2> {
let token = await knex('users').select(['token', 'perm']).where({ id: info.id })
let token = await knex('users').select(['token', 'perm']).where({ id: info.id || '' })
let t: string
if(!info.verified) return 1
if(token.length === 0) {
@ -342,7 +342,7 @@ async function assignToken(info: TokenRegister):Promise<string|1|2> {
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 }) })
token = await knex('users').select(['token']).where({ id: info.id })
} else await knex('users').update({ 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 }) }).where({ id: info.id })
if(token[0].perm !== 'user') return 2
if(token[0].perm && token[0].perm !== 'user') return 2
if(!verify(token[0]?.token ?? '')) {
t = sign({ id: info.id }, { expiresIn: '30d' })
await knex('users').update({ token: t }).where({ id: info.id })