2023-05-11 19:46:18 +02:00
|
|
|
import { applyUsername } from "~/server/utils/auth";
|
|
|
|
|
2023-04-28 16:56:36 +02:00
|
|
|
export default defineEventHandler(async (event) => {
|
2023-05-11 19:46:18 +02:00
|
|
|
const user = await getAuth(event)
|
2023-04-28 16:56:36 +02:00
|
|
|
|
2023-05-09 16:01:19 +02:00
|
|
|
if (!auth.minecraft.uuid) throw createError({ errorCode: 400, statusMessage: 'Geen Minecraft account is gekoppeld' })
|
2023-04-28 16:56:36 +02:00
|
|
|
|
2023-05-11 19:46:18 +02:00
|
|
|
const minecraftProfile = await $fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${user.minecraft.uuid}`)
|
2023-04-28 16:56:36 +02:00
|
|
|
|
|
|
|
const usersColl = db.collection('users')
|
2023-05-11 19:46:18 +02:00
|
|
|
const newUser = await usersColl.findOneAndUpdate({ 'minecraft.uuid': auth.minecraft.uuid }, { $set: { 'minecraft.username': minecraftProfile.name, username: user.useMinecraftUsername ? minecraftProfile.name : user.discord.username } }, { returnDocument: 'after' })
|
|
|
|
|
|
|
|
applyUsername(newUser.value)
|
2023-04-28 16:56:36 +02:00
|
|
|
|
2023-05-11 19:46:18 +02:00
|
|
|
return newUser.value
|
2023-04-28 16:56:36 +02:00
|
|
|
});
|