added beginning of whitelist system

This commit is contained in:
2023-04-25 15:51:20 +02:00
parent fa0a9b8e58
commit 796b156e8d
18 changed files with 421 additions and 80 deletions

View File

@@ -2,11 +2,12 @@ import jwt from 'jsonwebtoken'
const config = useRuntimeConfig()
export const createToken = (accessToken, refreshToken, maxAge) => {
return jwt.sign({ accessToken, refreshToken }, config.jwtSecret, {
export const createToken = (accessToken, refreshToken, maxAge, discordId) => {
return jwt.sign({ accessToken, refreshToken, discordId }, config.jwtSecret, {
expiresIn: maxAge,
})
}
export const getAuth = async (event) => {
const token = getCookie(event, 'jwt') || null
@@ -31,20 +32,9 @@ export const getAuth = async (event) => {
})
}
let userResult;
try {
userResult = await $fetch('https://discord.com/api/users/@me', {
headers: {
authorization: `Bearer ${decodedToken.accessToken}`
}
})
} catch (e) {
console.log(e)
}
try {
const coll = db.collection("users")
const user = await coll.findOne({ 'discord.id': userResult.id })
const user = await coll.findOne({ 'discord.id': decodedToken.discordId })
return user;
} catch (err) {