feat(server): delete cookie helper - #820
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughA new Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant CookieHelper
Client->>Server: Sends request with cookies in reqHeaders
Server->>CookieHelper: getCookie(reqHeaders, name)
CookieHelper-->>Server: Returns cookie value
Server->>CookieHelper: setCookie(resHeaders, name, value, options)
CookieHelper-->>Server: Sets cookie in resHeaders
Server->>CookieHelper: deleteCookie(resHeaders, name, options)
CookieHelper->>setCookie: Calls setCookie with value="" and maxAge=0
setCookie-->>CookieHelper: Sets expired cookie in resHeaders
CookieHelper-->>Server: Cookie deleted
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Summary of Changes
Hello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've added a new deleteCookie helper function to the server-side cookie utilities. This function simplifies the process of expiring cookies by setting their maxAge to zero, ensuring they are removed from the client's browser. This enhancement provides a more convenient and explicit way to manage cookie lifecycle.
Highlights
- New
deleteCookieFunction: I've introduced a newdeleteCookieutility function that simplifies the process of expiring HTTP cookies. This function internally leverages the existingsetCookiefunction by setting the cookie'sMax-Ageto 0, effectively instructing the client to remove it. - Comprehensive Testing: To ensure the reliability of the new
deleteCookiefunction, I've added a comprehensive suite of unit tests. These tests cover various scenarios, including basic cookie deletion, proper handling of additional cookie options (likepath), and graceful behavior when provided withundefinedheaders. - Documentation Update: The documentation for cookie helpers has been updated to include the newly added
deleteCookiefunction. I've also refined existing examples to clearly demonstrate its usage alongsidesetCookieandgetCookie, improving overall clarity by distinguishing between request and response headers.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Code Review
This pull request introduces a deleteCookie helper function, along with corresponding tests and documentation. The implementation is clean and follows best practices for cookie deletion. My review focuses on improving the clarity of the documentation examples, which are currently a bit confusing, and enhancing the robustness of the new tests. I've also suggested a minor stylistic improvement in the deleteCookie implementation itself.
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/react
@orpc/react-query
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/content/docs/helpers/cookie.md(2 hunks)packages/server/src/helpers/cookie.test.ts(2 hunks)packages/server/src/helpers/cookie.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/server/src/helpers/cookie.test.ts (1)
packages/server/src/helpers/cookie.ts (2)
setCookie(28-44)deleteCookie(83-92)
🪛 Biome (2.1.2)
packages/server/src/helpers/cookie.ts
[error] 88-91: The function should not return a value because its return type is void.
The function is here:
'void' signals the absence of value. The returned value is likely to be ignored by the caller.
(lint/correctness/noVoidTypeReturn)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: publish-commit
- GitHub Check: lint
- GitHub Check: test
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
packages/server/src/helpers/cookie.ts (1)
80-92: LGTM! Clean implementation of cookie deletion.The function correctly implements cookie deletion by setting
maxAge: 0, which is the standard approach to expire cookies immediately. The type safety withOmit<SetCookieOptions, 'maxAge'>prevents accidental override of the deletion behavior.apps/content/docs/helpers/cookie.md (2)
11-11: LGTM! Good addition of deleteCookie to imports.The import statement correctly includes the new
deleteCookiefunction alongside existing helpers.
13-24: Excellent improvement in documentation clarity.Separating request and response headers with distinct variable names (
reqHeadersandresHeaders) makes the examples much clearer and helps developers understand the proper context for each operation.packages/server/src/helpers/cookie.test.ts (2)
1-1: LGTM! Import statement correctly updated.The import statement properly includes
deleteCookiealongside existing functions.
117-138: Excellent comprehensive test coverage for deleteCookie.The test suite covers all essential scenarios:
- Basic deletion with
maxAge: 0verification- Options handling while correctly ignoring any provided
maxAge- Graceful handling of undefined headers
- Proper use of
@ts-expect-errorto document intentional type constraint testingThe tests validate both the functional behavior and type safety of the implementation.
Summary by CodeRabbit
New Features
Documentation
Tests