-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server-auth): dbAuth 3/3 - handle login, logout, signup, etc. re…
…quests if forwarded from middleware (#10457) Co-authored-by: David Thyresson <dthyresson@gmail.com>
- Loading branch information
1 parent
bd82da2
commit dca417f
Showing
6 changed files
with
395 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
- feat(server-auth): dbAuth 3/3 - handle login, logout, signup, etc. requests if forwarded from middleware (#10457) by @dac09 | ||
|
||
This PR updates the DbAuthHandler class to handle requests forwarded from middleware, so it can generate responses for login, logout, signup, etc. These are POST requests - it used to be to the `/auth` function, but now they will be captured by dbAuth middleware and forwarded onto DbAuthHandler. | ||
|
||
**High level changes:** | ||
- use the `Headers` class in each of the "method" responses. This allows us to set multi-value headers like Set-Cookie. A simple object would not. See type `AuthMethodOutput` | ||
- extracts `buildResponse` into a testable function and adds test. For `Set-Cookie` headers we return an array of strings. | ||
|
||
In the middleware here's the code I had for the final conversion: | ||
```ts | ||
if (AUTHHANDLER_REQUEST) { | ||
const output = await dbAuthHandler(req) | ||
|
||
const finalHeaders = new Headers() | ||
Object.entries(output.headers).forEach(([key, value]) => { | ||
if (Array.isArray(value)) { | ||
value.forEach((v) => finalHeaders.append(key, v)) | ||
} else { | ||
finalHeaders.append(key, value) | ||
} | ||
}) | ||
|
||
return new MiddlewareResponse(output.body, { | ||
headers: finalHeaders, | ||
status: output.statusCode, | ||
}) | ||
} | ||
``` |
Oops, something went wrong.