Sveltekit actions error #1150

Closed
opened 2026-03-13 08:25:12 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @weepy on GitHub (May 1, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. create a typical sveltekit project
  2. add a hooks.server.js file

Current vs. Expected behavior

Hiya,
I've integrated better-auth into my sveltekit app. All going smoothly until i git the actions.

I have a hooks.server.js that looks like:

import { auth } from "$lib/auth"; // path to your auth file
import { svelteKitHandler } from "better-auth/svelte-kit";

export async function handle({ event, resolve }) {
    svelteKitHandler({ event, resolve, auth });
    const session = await auth.api.getSession({
        headers: event.request.headers
    })
   
    if (!session) {
        return new Response("Unauthorized", { status: 401 })
    }
    event.locals.session = session?.session;
    event.locals.user = session?.user;
    return resolve(event);
}

which is all groovy, but then when I try and grab stuff from the body in an action ...
E.g.


export async function POST({  reques, locals }) {
    const body = await request.json(); // <<<<< Error: Body is not usable.

I get this error because I guess the sveltekitHandler has already done this.

How should I handle this ?

What version of Better Auth are you using?

latest

Provide environment information

- Chrome, Macos

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @weepy on GitHub (May 1, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. create a typical sveltekit project 2. add a hooks.server.js file ### Current vs. Expected behavior Hiya, I've integrated better-auth into my sveltekit app. All going smoothly until i git the actions. I have a hooks.server.js that looks like: ```js import { auth } from "$lib/auth"; // path to your auth file import { svelteKitHandler } from "better-auth/svelte-kit"; export async function handle({ event, resolve }) { svelteKitHandler({ event, resolve, auth }); const session = await auth.api.getSession({ headers: event.request.headers }) if (!session) { return new Response("Unauthorized", { status: 401 }) } event.locals.session = session?.session; event.locals.user = session?.user; return resolve(event); } ```` which is all groovy, but then when I try and grab stuff from the body in an action ... E.g. ```js export async function POST({ reques, locals }) { const body = await request.json(); // <<<<< Error: Body is not usable. ```` I get this error because I guess the sveltekitHandler has already done this. How should I handle this ? ### What version of Better Auth are you using? latest ### Provide environment information ```bash - Chrome, Macos ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
Author
Owner

@ezShroom commented on GitHub (Jun 16, 2025):

@weepy how did you solve this?

@ezShroom commented on GitHub (Jun 16, 2025): @weepy how did you solve this?
Author
Owner

@weepy commented on GitHub (Jun 16, 2025):

I solved it by not using better-auth

@weepy commented on GitHub (Jun 16, 2025): I solved it by not using better-auth
Author
Owner

@screenfluent commented on GitHub (Jul 9, 2025):

I solved it by not using better-auth

What did you choose? Or maybe own auth as I'm about to ditch it as well...

@screenfluent commented on GitHub (Jul 9, 2025): > I solved it by not using better-auth What did you choose? Or maybe own auth as I'm about to ditch it as well...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1150