Polarcraft/web/server/api/minecraft/verifyuuid.js

31 lines
797 B
JavaScript
Raw Normal View History

2023-04-25 15:51:20 +02:00
export default defineEventHandler(async (event) => {
const auth = getAuth(event)
const { uuid } = await readBody(event)
const coll = db.collection('whitelist')
const doc = await coll.findOne({ uuid: uuid })
if (doc && !doc.verified) return { code: doc.code, verified: false }
if (doc && doc.verified) return { verified: true }
await coll.createIndex({ code: 1 }, { unique: true })
const code = await insertDoc(coll, uuid)
return { code: code.toString(), verified: false }
});
const insertDoc = async (coll, uuid) => {
try {
const code = Math.floor(100000 + Math.random() * 900000)
await coll.insertOne({ uuid: uuid, verified: false, code: code.toString() })
return code;
} catch (e) {
const code = await insertDoc(coll, uuid)
return code;
}
}