created basic auth system

This commit is contained in:
2023-04-23 17:16:53 +02:00
parent 70f18f75df
commit fa0a9b8e58
10 changed files with 360 additions and 15 deletions

View File

@@ -20,6 +20,24 @@ export default defineEventHandler(async (event) => {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
const userResult = await $fetch('https://discord.com/api/users/@me', {
headers: {
authorization: `Bearer ${tokenResponseData.access_token}`
}
})
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, $setOnInsert: { minecraft: { uuid: null, username: null }, team: null } }, { upsert: true })
const token = createToken(tokenResponseData.access_token, tokenResponseData.refresh_token, tokenResponseData.expires_in)

View File

@@ -0,0 +1,5 @@
export default defineEventHandler(async (event) => {
const auth = getAuth(event)
return auth
});