Polarcraft/webv2/server/api/users/[id]/username.put.ts

17 lines
495 B
TypeScript

export default defineEventHandler(async (event) => {
const { usernameType } = await readBody(event)
const userId: string = event.context.params ? event.context.params.id : '@me'
if (usernameType !== 'discord' && usernameType !== 'minecraft') {
throw createError({ statusCode: 400, statusMessage: 'UsernameType must be discord or minecraft' })
}
const user = await getUser(userId, event)
user.usernameType = usernameType
await applyUsername(user)
return user.username
})