created basic auth system
This commit is contained in:
@@ -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)
|
||||
|
||||
|
5
web/server/api/auth/user/index.js
Normal file
5
web/server/api/auth/user/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const auth = getAuth(event)
|
||||
|
||||
return auth
|
||||
});
|
Reference in New Issue
Block a user