Formatted all files with Prettier
This commit is contained in:
parent
0bc2196d9f
commit
ea80456a56
64 changed files with 2209 additions and 1839 deletions
|
@ -10,40 +10,48 @@ import { Logging } from "../../lib/backend/logging"
|
|||
import { Token } from "@prisma/client"
|
||||
|
||||
interface Data {
|
||||
token: string
|
||||
token: string
|
||||
}
|
||||
|
||||
export default async function auth(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
return getTokenFromCookie({ req, res, newTokenType: 'ACCESS' as Token['type'] })
|
||||
.then(checkTokenIsValid)
|
||||
.then(getTokenDB)
|
||||
.then(getPlayerByIdDB)
|
||||
.then(createTokenDB)
|
||||
.then(authResponse<Data>)
|
||||
.then(sendResponse<Data>)
|
||||
.catch(err => sendError(req, res, err))
|
||||
return getTokenFromCookie({
|
||||
req,
|
||||
res,
|
||||
newTokenType: "ACCESS" as Token["type"],
|
||||
})
|
||||
.then(checkTokenIsValid)
|
||||
.then(getTokenDB)
|
||||
.then(getPlayerByIdDB)
|
||||
.then(createTokenDB)
|
||||
.then(authResponse<Data>)
|
||||
.then(sendResponse<Data>)
|
||||
.catch((err) => sendError(req, res, err))
|
||||
}
|
||||
|
||||
async function authResponse<T>(payload: {
|
||||
newToken: string,
|
||||
newTokenDB: Token,
|
||||
tokenDB: Token,
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<T>
|
||||
newToken: string
|
||||
newTokenDB: Token
|
||||
tokenDB: Token
|
||||
req: NextApiRequest
|
||||
res: NextApiResponse<T>
|
||||
}) {
|
||||
const { newToken, newTokenDB, tokenDB, req, res } = payload
|
||||
const { newToken, newTokenDB, tokenDB, req, res } = payload
|
||||
|
||||
// Successfull response
|
||||
return {
|
||||
req,
|
||||
res,
|
||||
result: {
|
||||
message: 'Access-Token generated: ' + newTokenDB.id + ' with Refreshtoken-Token: ' + tokenDB.id,
|
||||
body: { token: newToken },
|
||||
type: ['debug', 'info.cyan'] as Logging[]
|
||||
}
|
||||
}
|
||||
}
|
||||
// Successfull response
|
||||
return {
|
||||
req,
|
||||
res,
|
||||
result: {
|
||||
message:
|
||||
"Access-Token generated: " +
|
||||
newTokenDB.id +
|
||||
" with Refreshtoken-Token: " +
|
||||
tokenDB.id,
|
||||
body: { token: newToken },
|
||||
type: ["debug", "info.cyan"] as Logging[],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue