Skip to content
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

feat(backend): Set cookies from the refresh token flow #4884

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

brkalow
Copy link
Member

@brkalow brkalow commented Jan 13, 2025

Description

Supports the format=cookies parameter for the session refresh endpoint. When this parameter is passed, the API will return an array of set-cookie header values to be passed along with the response.

SDKI-832

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Jan 13, 2025

🦋 Changeset detected

Latest commit: 3998837

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@clerk/backend Minor
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-start Patch
@clerk/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ⬜️ Skipped (Inspect) Jan 15, 2025 2:58am

return HttpResponse.json(mockJwks);
}),
);
describe('refreshToken', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these tests into a separate describe block, consider looking at the diff without whitespace to see the actual changes: https://github.com/clerk/javascript/pull/4884/files?w=1

@brkalow brkalow marked this pull request as ready for review January 14, 2025 03:58
@brkalow brkalow requested a review from a team January 14, 2025 03:58
packages/backend/src/api/endpoints/SessionApi.ts Outdated Show resolved Hide resolved
@@ -273,14 +273,16 @@ ${error.getFullMessage()}`,

try {
// Perform the actual token refresh.
const tokenResponse = await options.apiClient.sessions.refreshSession(decodeResult.payload.sid, {
const response = await options.apiClient.sessions.refreshSession(decodeResult.payload.sid, {
format: 'cookie',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this to be set for every call ? Could this be configured and passed down from authenticateRequest ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a good reason to make it configurable, not setting the cookie allows requests to fire with the expired session token before clerk-js hydrates.

Co-authored-by: panteliselef <panteliselef@outlook.com>
@brkalow brkalow requested a review from a team January 15, 2025 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants