-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow.ts
46 lines (40 loc) · 990 Bytes
/
workflow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { NextFunction, Request, Response } from 'express'
import Joi from 'joi'
import runner from './runner'
/**
* Refresh Token Request Schema:
* `refreshToken` should be passed in body
*/
export const requestSchema = Joi.object({
body: Joi.object({
refreshToken: Joi.string().required()
}),
query: Joi.object(),
params: Joi.object()
})
/**
* refresh Token Response Schema:
* {`accessToken`, `refreshToken`}
*/
export const responseSchema = Joi.object({
accessToken: Joi.string().required(),
refreshToken: Joi.string().required()
})
/**
* Endpoint for refreshing token
* Usage: `router.use('/refresh-token', schemaMiddleware(RefreshToken.requestSchema), RefreshToken.endpoint)`
* @param req
* @param res
* @param next
*/
export async function workflow(req: Request, res: Response, next: NextFunction) {
try {
const { body } = req
const tokens = await runner(body.refreshToken, req)
return res.json({
...tokens
})
} catch (e) {
return next(e)
}
}