[GH-ISSUE #808] Updating cookies using server API #25770

Closed
opened 2026-04-17 16:02:40 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @octet-stream on GitHub (Dec 7, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/808

Is your feature request related to a problem? Please describe.

Hi, I've been working on better auth integration in my React Router 7, and I can't find a way to get updated session cookie from the server API. As far as I can see, this code from getSession route is managing session cookie (it deletes or renews one), but I don't see how I can get this cookie, so I can set it on the server myself. This is a blocker for me, because I rely on the server API to get this job done.

Describe the solution you'd like

I think this method should either return cookie (which is likely bad idea, since server reuses same API as the client via better-call as far as I understand, so this data should not get to a browser) along with user and session, or just allow asResponse flag as in some of the other methods, so I can access it from the Response object. I don't mind to do some extra work to get session and user from the response's body (I also need those), because there's a clear way to do it.

Describe alternatives you've considered

None

Additional context

Essentially I need do this:

image

This code gets headers from Response object returned by signInEmail, then just assigns it to replace function that will send these headers to browser and redirect user.

Originally created by @octet-stream on GitHub (Dec 7, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/808 **Is your feature request related to a problem? Please describe.** Hi, I've been working on better auth integration in my React Router 7, and I can't find a way to get updated session cookie from the server API. As far as I can see, [this code](https://github.com/better-auth/better-auth/blob/58ad15dd52aafc747fb8e176b4af2ac573ff2d84/packages/better-auth/src/api/routes/session.ts#L212-L222) from `getSession` route is managing session cookie (it deletes or renews one), but I don't see how I can get this cookie, so I can set it on the server myself. This is a blocker for me, because I rely on the server API to get this job done. **Describe the solution you'd like** I think this method should either return cookie (which is likely bad idea, since server reuses same API as the client via better-call as far as I understand, so this data should not get to a browser) along with user and session, or just allow `asResponse` flag as in some of the other methods, so I can access it from the Response object. I don't mind to do some extra work to get session and user from the response's body (I also need those), because there's a clear way to do it. **Describe alternatives you've considered** None **Additional context** Essentially I need do this: <img width="406" alt="image" src="https://github.com/user-attachments/assets/17e75c04-ae02-4bf1-9b7c-5f2c7ccad31a"> This code gets headers from Response object returned by `signInEmail`, then just assigns it to `replace` function that will send these headers to browser and redirect user.
GiteaMirror added the locked label 2026-04-17 16:02:40 -05:00
Author
Owner

@octet-stream commented on GitHub (Dec 8, 2024):

Turns out, I can use asResponse option, even though ts says there's no such field on this object. And it works!

image image

So, the only change is needed as in type declarations for this method.

<!-- gh-comment-id:2525384266 --> @octet-stream commented on GitHub (Dec 8, 2024): Turns out, I can use `asResponse` option, even though ts says there's no such field on this object. And it works! <img width="346" alt="image" src="https://github.com/user-attachments/assets/92c6f407-04fb-47e7-aeba-98dc4d0fd65c"> <img width="599" alt="image" src="https://github.com/user-attachments/assets/4c22924f-010c-4584-8b62-600d9cfb89cc"> So, the only change is needed as in type declarations for this method.
Author
Owner

@octet-stream commented on GitHub (Dec 8, 2024):

@Bekacru Thanks for quick fix! But I updated to v1.0.11 and the return type is still broken. Though I can confirms params type is correct now.

image
<!-- gh-comment-id:2525933829 --> @octet-stream commented on GitHub (Dec 8, 2024): @Bekacru Thanks for quick fix! But I updated to v1.0.11 and the return type is still broken. Though I can confirms params type is correct now. <img width="684" alt="image" src="https://github.com/user-attachments/assets/aee8c86f-92cb-49cc-a6ee-4d7770b6d1da">
Author
Owner

@Bekacru commented on GitHub (Dec 8, 2024):

Hey @octet-stream thanks for pinging me. Should be fixed on 1.0.13

<!-- gh-comment-id:2525971649 --> @Bekacru commented on GitHub (Dec 8, 2024): Hey @octet-stream thanks for pinging me. Should be fixed on `1.0.13`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25770