Polarcraft/webv2/server/api/minecraft/verifyaccount.get.ts
Xeovalyte d74a51db7f
All checks were successful
Build and Deploy / Deploy Web (push) Successful in 1m2s
Build and Deploy / Deploy Discord Bot (push) Successful in 44s
feat: Added verify account route, closes #28
2023-06-05 16:05:03 +02:00

25 lines
598 B
TypeScript

export default defineEventHandler(async (event) => {
const { uuid } = getQuery(event)
let whitelistDoc
try {
whitelistDoc = await WhitelistModel.findOneAndUpdate({ uuid }, {
$set: {
uuid
},
$setOnInsert: {
code: generateCode(),
connected: false
}
}, { returnDocument: 'after', upsert: true })
return whitelistDoc
} catch (e: any) {
throw createError({ statusCode: 500, statusMessage: 'Failed to update/insert whitelist document' })
}
})
const generateCode = () => {
return Math.floor(100000 + Math.random() * 900000)
}