"State not found" error

I'm trying to sign in using apple, but I'm getting this error:
Error Code: state_not_found
Error Code: state_not_found
According to this code it tries to get the state from the body of the request (in case if it is POST). The thing is I console.loged body and it has the state parameter. I'm using fastify and the following code to convert fastify request to regular one:
const body = request.body ? JSON.stringify(request.body) : undefined;

console.log('body', body);
// { state: 'AAA', code: 'BBB', id_token: 'CCC' }

const req = new Request(url.toString(), {
method: request.method,
headers,
body,
});
const body = request.body ? JSON.stringify(request.body) : undefined;

console.log('body', body);
// { state: 'AAA', code: 'BBB', id_token: 'CCC' }

const req = new Request(url.toString(), {
method: request.method,
headers,
body,
});
GitHub
better-auth/packages/better-auth/src/api/routes/callback.ts at 8fbe...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
1 Reply
eden_lane
eden_laneOP2mo ago
Looks like it's a bug, Request body cannot be parsed by zod...

Did you find this page helpful?