Formatted all files with Prettier
This commit is contained in:
parent
0bc2196d9f
commit
ea80456a56
64 changed files with 2209 additions and 1839 deletions
|
@ -2,27 +2,29 @@ import { Token } from "@prisma/client"
|
|||
import jwt from "jsonwebtoken"
|
||||
import jwtVerifyCatch from "../jwtVerifyCatch"
|
||||
|
||||
async function checkTokenIsValid<T>(payload: T & { token: string, tokenType: Token['type'] }) {
|
||||
const { token, tokenType } = payload
|
||||
async function checkTokenIsValid<T>(
|
||||
payload: T & { token: string; tokenType: Token["type"] }
|
||||
) {
|
||||
const { token, tokenType } = payload
|
||||
|
||||
// Verify the token and get the payload
|
||||
let tokenData: string | jwt.JwtPayload
|
||||
try {
|
||||
tokenData = jwt.verify(token, process.env.ACCESS_TOKEN_SECRET as string)
|
||||
} catch (err: any) {
|
||||
// Deal with the problem in more detail
|
||||
return Promise.reject(jwtVerifyCatch(tokenType, err))
|
||||
}
|
||||
// Making sure the token data is not a string (because it should be an object)
|
||||
if (typeof tokenData === 'string') {
|
||||
return Promise.reject({
|
||||
message: tokenType + '-Token data was a string. Token: ' + token,
|
||||
statusCode: 401,
|
||||
solved: false
|
||||
})
|
||||
}
|
||||
// Verify the token and get the payload
|
||||
let tokenData: string | jwt.JwtPayload
|
||||
try {
|
||||
tokenData = jwt.verify(token, process.env.ACCESS_TOKEN_SECRET as string)
|
||||
} catch (err: any) {
|
||||
// Deal with the problem in more detail
|
||||
return Promise.reject(jwtVerifyCatch(tokenType, err))
|
||||
}
|
||||
// Making sure the token data is not a string (because it should be an object)
|
||||
if (typeof tokenData === "string") {
|
||||
return Promise.reject({
|
||||
message: tokenType + "-Token data was a string. Token: " + token,
|
||||
statusCode: 401,
|
||||
solved: false,
|
||||
})
|
||||
}
|
||||
|
||||
return { ...payload, tokenBody: token, tokenIsValid: true }
|
||||
return { ...payload, tokenBody: token, tokenIsValid: true }
|
||||
}
|
||||
|
||||
export default checkTokenIsValid
|
||||
export default checkTokenIsValid
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue