Polarcraft/web/server/api/auth/user/setdefaultusername.js

16 lines
491 B
JavaScript
Raw Normal View History

2023-05-09 15:23:31 +02:00
import { ObjectId } from "mongodb";
export default defineEventHandler(async (event) => {
const { type } = await readBody(event)
const auth = await getAuth(event)
const usersColl = db.collection('users')
const username = type === 'discord' ? auth.discord.username : auth.minecraft.username
await usersColl.updateOne({ _id: new ObjectId(auth._id) }, { $set: { username: username, useMinecraftUsername: type === 'discord' ? false : true } })
return { username: username }
});