Added username switching
This commit is contained in:
23
web/server/api/discord/refreshusername.js
Normal file
23
web/server/api/discord/refreshusername.js
Normal file
@@ -0,0 +1,23 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const auth = await getAuth(event)
|
||||
|
||||
const userResult = await $fetch('https://discord.com/api/users/@me', {
|
||||
headers: {
|
||||
authorization: `Bearer ${auth.accessToken}`
|
||||
}
|
||||
})
|
||||
|
||||
const coll = db.collection('users')
|
||||
|
||||
const doc = {
|
||||
discord: {
|
||||
id: userResult.id,
|
||||
username: userResult.username,
|
||||
avatarHash: userResult.avatar || null
|
||||
},
|
||||
}
|
||||
|
||||
await coll.updateOne({ 'discord.id': userResult.id }, { $set: doc })
|
||||
|
||||
return doc.discord
|
||||
});
|
Reference in New Issue
Block a user