Error with Immutable Headers in Better Auth Session Middleware on Deno Server
Guys
Hello ,
I’m working on setting up session management using Better Auth with a Deno server and Hono as the framework. I followed the documentation to create a middleware for session handling, but I'm running into an issue when trying to retrieve sessions.
Here’s a simplified version of my code:
Issue Details
Upon running the server, I receive the following error:
The error occurs when the
getSession
method is called, indicating that headers are treated as immutable. I attempted the workaround of using raw headers directly from c.req.raw.headers
, but this hasn’t resolved the issue.
Environment
- Deno: 2.0.2
- Better Auth: v0.6.2
- Hono: v4.6.8
3 Replies
Steps Taken
1. Verified with
auth.api.getSession({ headers })
as shown in the documentation.
2. Attempted direct access to raw headers as a possible workaround.
Any insights into resolving this immutable headers issue would be greatly appreciated. Thanks for your help!
https://www.better-auth.com/docs/integrations/honoHono Integration | Better Auth
Hono Integration Guide
GitHub
better-auth-example/plugin-server/src/middleware/sessionMiddleware....
Contribute to jacksonkasi1/better-auth-example development by creating an account on GitHub.
Hey everyone,
I realized my issue with the immutable headers error was a simple oversight. I needed to clone the headers to avoid immutability. Here’s the quick fix:
This small change did the trick! Just sharing in case anyone else runs into the same thing.