SvelteKit Client + BetterAuth Hono.js = Proper Setup and Cookie Issues?

I have been struggling with this for quite some time. 1. I am soley doing everything on client in SvelteKit (app.business.local) 2. I have a separate Hono.js server that is running betterAuth. I can successfully make calls to it (api.app.business.local). Questions: 1. How do I properly check that a user is authenticated? authClient.getSession() do I pass anything to it? 2. Where do I check that a user is authenticated? Its not hooks.server.ts is it? Because this is really a relationship between client of SvelteKit and Hono.js server. Current check is in hooks.server.ts, but the authClient.getSession() is always null. so it always kicks me out of dashboard on hard refresh. I am goto() client side redirecting after successful login. 3. On successful login locally, I get a businesss.session_token: - When remember me is checked 7 day expiration - HttpOnly: Yes - SameSite: Lax I get redirected with goto() to authenticated route, but this is client side navigation. On hard refresh I get kicked out, because I always get null on hook.server.ts for session. On refresh cookie disappears.
4 Replies
Acro
AcroOP2mo ago
This is solved…passed cookie to header in hooks.server.ts Cross domain setup on betterAuth setup.
Adam
Adam2mo ago
Hey, how did you get this running? I have enabled cross domain setup and still does not work. The cookies get created and instantly nuked afterwards in the frontend.
No description
No description
No description
Acro
AcroOP2mo ago
What does your Chrome dev tools show for cookies? If its yellow, it will tell you what is wrong
Adam
Adam2mo ago
ended up ditching the approach of having two separate services for a sveltekit monorepo, now it all works fine, and I can do proper auth validation on the sveltekit server routes/hooks

Did you find this page helpful?