Polarcraft/webv2/server/api/minecraft/verifyaccount.get.ts

25 lines
598 B
TypeScript
Raw Normal View History

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)
}