* For the refresh_token endpoint, inject the refresh_token from cookie * into the request body so the backend can process it normally. * If no refresh_token cookie exists, return 401 immediately.
(pathname, body, cookies, res)
| 182 | * If no refresh_token cookie exists, return 401 immediately. |
| 183 | */ |
| 184 | function prepareAuthRequestBody(pathname, body, cookies, res) { |
| 185 | if ( |
| 186 | pathname === "/api/user/refresh_token" ) { |
| 187 | const refreshToken = |
| 188 | cookies[COOKIE_NAMES.REFRESH_TOKEN] |
| 189 | ; |
| 190 | if (!refreshToken) { |
| 191 | res.writeHead(401, { "Content-Type": "application/json" }); |
| 192 | res.end(JSON.stringify({ detail: "No refresh token cookie found" })); |
| 193 | return null; |
| 194 | } |
| 195 | try { |
| 196 | const parsed = body.length > 0 ? JSON.parse(body.toString()) : {}; |
| 197 | parsed.refresh_token = refreshToken; |
| 198 | return Buffer.from(JSON.stringify(parsed)); |
| 199 | } catch { |
| 200 | return body; |
| 201 | } |
| 202 | } |
| 203 | return body; |
| 204 | } |
| 205 | |
| 206 | function forwardAuthRequest(req, res, targetUrl) { |
| 207 | const parsedTarget = new URL(targetUrl); |
no test coverage detected