(req: any, res: any)
| 68 | // let usedTokens: Record<string, boolean> = {}; |
| 69 | |
| 70 | export async function refreshTokenAction(req: any, res: any) { |
| 71 | const token = getToken(req); |
| 72 | if (!token) { |
| 73 | throw new Error('Token not found'); |
| 74 | } |
| 75 | |
| 76 | // if (usedTokens[token]) { |
| 77 | // throw new Error('Token already used'); |
| 78 | // } |
| 79 | |
| 80 | const isValid = (await verifyToken(token)) as JwtPayload; |
| 81 | const newToken = await signToken(isValid.data); |
| 82 | |
| 83 | // TODO: add refreshToken used on some external black-list |
| 84 | // usedTokens[token] = true; |
| 85 | |
| 86 | // persist cookies for SSR |
| 87 | setSessionCookies({ |
| 88 | token: newToken, |
| 89 | req, |
| 90 | res, |
| 91 | }); |
| 92 | |
| 93 | return { newToken }; |
| 94 | } |
no test coverage detected