-
-
Notifications
You must be signed in to change notification settings - Fork 37
feat: Cookies #3406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: Cookies #3406
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
58f5e1c
feat(config): Cookies input source and parser.
RobinTail ac63403
feat(server): add cookie-parser dynamic intergration.
RobinTail e1adad4
feat(mw): Add cookieMiddleware (public).
RobinTail ac3d1da
feat(Documentation): add cookie request parameter depiction based on …
RobinTail 9493c14
feat(docs): Readme article draft and Changelog 28.1.0.
RobinTail a229dcc
feat(deps): Add cookie parser and its types as optional peer dependen…
RobinTail e49fe00
fix(server): createCookieParser() to load the cookie-parser peer type…
RobinTail 111807a
fix(config): Reusing the cookie-parser types to describe options.
RobinTail eeeddc3
fix(mw): add jsdoc to cookieMiddleware.
RobinTail 4ca3be2
feat(mw): createCookieMiddleware.
RobinTail 519dede
fix(jsdoc): minor.
RobinTail 34d19bb
ref(server): shortening createCookieParser.
RobinTail 0eb0fb1
fix(test): placing cookies into makeRequestMock.
RobinTail b61fb21
fix(test): shortening for getInput().
RobinTail 6e3bdb1
fix(test): naming.
RobinTail 9b910a9
rm(test): redundant in config type.
RobinTail fbb196f
fix(test): using testMiddleware for createCookieMiddleware.
RobinTail f94a48d
fix(test): simpler test for server parser.
RobinTail d164e26
fix(test): rm redundant endpoints from server test.
RobinTail 2f9fb53
fix(test): simpler mock.
RobinTail 6b10f17
fix(config): rm second jsdoc.
RobinTail d43a7da
fix(test): shortening documentation test.
RobinTail 75715ee
feat: getSecurityNames() helper for extracting either cookies or head…
RobinTail 76d7768
minor: naming.
RobinTail 7075c9b
fix(docs): Readme shortening.
RobinTail 566032d
fix(docs): upd index.
RobinTail 326b419
Changelog: 28.1.0.
RobinTail 3f8168f
Add cookies to dataflow diagram
RobinTail cbfc6f9
fix(docs): transparent edges of the diagram.
RobinTail 3838f1c
rm the plan.
RobinTail 68561e0
fix(mw): rm double jsdoc and renaming overriding options more clearly.
RobinTail 9d00043
feat(mw): support object-based values on setCookie.
RobinTail baab135
fix(mw): resuing Zod's JSONType.
RobinTail 29a5367
rm redundant example.
RobinTail d7ef9e3
feat: getCookie, alternative flexible approach, versatility reflectin…
RobinTail 3f5f9a2
Update CHANGELOG.md
RobinTail daed650
feat(example): the cookie reading and writing tests.
RobinTail 14e6768
fix(example): more jsdoc.
RobinTail d50b262
fix(example): simpler login.
RobinTail 466de37
fix(example): better auth assertion.
RobinTail 9dd8e37
fix(example): required params for login endpoint.
RobinTail a1aba6e
fix(mw): clearCookie omits 'expires' and 'maxAge' options, value 1 is…
RobinTail 4a0a138
fix(docs): Reflecting recommended security measures in Readme.
RobinTail aebec21
fix(example): applying best cookie practice on test.
RobinTail bbde2f5
fix(example): using scrypt instead of hash sha1.
RobinTail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
This file contains hidden or 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,31 @@ | ||
| import { cookieAssistedFactory } from "../factories.ts"; | ||
| import { z } from "zod"; | ||
| import { randomUUID, scrypt } from "node:crypto"; | ||
| import createHttpError from "http-errors"; | ||
| import assert from "node:assert/strict"; | ||
| import { promisify } from "node:util"; | ||
|
|
||
| /** @desc The endpoint demonstrates setting a cookie */ | ||
| export const loginEndpoint = cookieAssistedFactory.build({ | ||
| method: "post", | ||
| tag: "cookies", | ||
| input: z.object({ | ||
| username: z.string().trim().nonempty(), | ||
| password: z.string().trim().nonempty(), | ||
| }), | ||
| output: z.object({ message: z.string() }), | ||
| handler: async ({ input: { username, password }, ctx: { setCookie } }) => { | ||
| const key = await promisify<string, string, number, Buffer>(scrypt)( | ||
| password, | ||
| "kinda salt", | ||
| 16, | ||
| ); | ||
| assert( | ||
| username === "admin" && | ||
| key.toString("hex") === "79ad19b8c03bc92a2f25ed865400264e", | ||
| createHttpError(401, "Invalid credentials"), | ||
| ); | ||
| setCookie("session", { token: randomUUID() }); | ||
|
RobinTail marked this conversation as resolved.
|
||
| return { message: "Logged in" }; | ||
| }, | ||
| }); | ||
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.