added whitelist system

This commit is contained in:
2023-04-28 16:56:36 +02:00
parent cafa230433
commit 99c7ef381d
5 changed files with 85 additions and 12 deletions

View File

@@ -0,0 +1,12 @@
export default defineEventHandler(async (event) => {
const auth = await getAuth(event)
if (!auth.minecraft.uuid) throw createError({ errorCode: 400, statusMessage: 'No Minecraft account is linked' })
const minecraftProfile = await $fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${auth.minecraft.uuid}`)
const usersColl = db.collection('users')
await usersColl.findOneAndUpdate({ 'minecraft.uuid': auth.minecraft.uuid }, { $set: { 'minecraft.username': minecraftProfile.name } })
return { username: minecraftProfile.name }
});

View File

@@ -0,0 +1,13 @@
export default defineEventHandler(async (event) => {
const auth = await getAuth(event)
if (!auth.minecraft.uuid) throw createError({ errorCode: 400, statusMessage: 'No Minecraft account is linked' })
const whitelistColl = db.collection('whitelist')
await whitelistColl.deleteOne({ uuid: auth.minecraft.uuid })
const usersColl = db.collection('users')
await usersColl.findOneAndUpdate({ 'minecraft.uuid': auth.minecraft.uuid }, { $set: { 'minecraft.uuid': null, 'minecraft.username': null } })
return { code: 'success' }
});

View File

@@ -1,6 +1,4 @@
export default defineEventHandler(async (event) => {
const auth = getAuth(event)
const { uuid } = await readBody(event)
const coll = db.collection('whitelist')

View File

@@ -3,7 +3,6 @@ export default defineEventHandler(async (event) => {
if (!code) throw createError({ statusCode: 400, statusMessage: 'Code is required'})
const config = useRuntimeConfig()
const auth = await getAuth(event)
const whitelistColl = db.collection('whitelist')
@@ -14,9 +13,11 @@ export default defineEventHandler(async (event) => {
await whitelistColl.updateOne({ code: code.toString() }, { $set: { verified: true } })
const minecraftProfile = await $fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${whitelistDoc.uuid}`)
const usersColl = db.collection('users')
await usersColl.updateOne({ 'discord.id': auth.discord.id }, { $set: { 'minecraft.uuid': whitelistDoc.uuid } })
await usersColl.updateOne({ 'discord.id': auth.discord.id }, { $set: { 'minecraft.uuid': whitelistDoc.uuid, 'minecraft.username': minecraftProfile.name } })
return { uuid: whitelistDoc.uuid, verified: false }
return { uuid: whitelistDoc.uuid, verified: false, username: minecraftProfile.name }
});