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