2023-06-05 22:41:48 +02:00
|
|
|
export default defineEventHandler(async (event) => {
|
|
|
|
const userId: string = event.context.params ? event.context.params.id : '@me'
|
|
|
|
|
|
|
|
const user = await getUser(userId, event)
|
|
|
|
|
2023-06-06 10:37:30 +02:00
|
|
|
if (user.$isEmpty('minecraft') || !user.minecraft) {
|
2023-06-05 22:41:48 +02:00
|
|
|
throw createError({ statusCode: 400, statusMessage: 'Minecraft has not been linked' })
|
|
|
|
}
|
|
|
|
|
|
|
|
const minecraftProfile: any = await $fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${user.minecraft.uuid}`)
|
|
|
|
|
|
|
|
try {
|
|
|
|
user.minecraft = { uuid: user.minecraft.uuid, username: minecraftProfile.name }
|
|
|
|
|
2023-06-06 10:37:30 +02:00
|
|
|
await user.save()
|
2023-06-05 22:41:48 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.error('Failed to update document', e)
|
|
|
|
|
|
|
|
throw createError('Failed to update document')
|
|
|
|
}
|
|
|
|
|
|
|
|
return user.minecraft
|
|
|
|
})
|