T
TanStack2w ago
adverse-sapphire

Typescript error with server functions with the GET method

I migrated successfully my app to RC, I have only one issue with server functions using the get method, like this one
export const getUserSession = createServerFn({
method: 'GET',
}).handler(async () => {
const request = getRequest();

if (!request.headers) {
return null;
}

const userSession = await auth.api.getSession({ headers: request.headers });

return userSession;
});
export const getUserSession = createServerFn({
method: 'GET',
}).handler(async () => {
const request = getRequest();

if (!request.headers) {
return null;
}

const userSession = await auth.api.getSession({ headers: request.headers });

return userSession;
});
now I have this error: the types of 'options.query.unwrap' are incompatible between these types. Type '(() => ZodObject<{ disableCookieCache: ZodOptional<ZodCoercedBoolean<unknown>>; disableRefresh: ZodOptional<ZodCoercedBoolean<unknown>>; }, $strip>) & (() => ZodObject<...>)' is not assignable to type '"Function is not serializable"'
4 Replies
unwilling-turquoise
unwilling-turquoise2w ago
It sounds like theres a function somewhere in userSession, but I can't see the connection between your code block and the zod errors Or what your auth provider is If you can put this in a codesandbox or stackblitz that would be helpful (If you have a function in an object the object cant be serialised to Json)
optimistic-gold
optimistic-gold2w ago
dont use getRequest, use getRequestHeaders directly, as in
return auth.api.getSession({
headers: getRequestHeaders(),
});
return auth.api.getSession({
headers: getRequestHeaders(),
});
`
stormy-gold
stormy-gold2w ago
Sounds like you are using Zod v4 with their z.coerce.boolean() schema. Try specifying the type so it is not inferred as unknown: z.coerce.boolean<boolean>()
adverse-sapphire
adverse-sapphireOP2w ago
this is a demo app showcasing how to integrate better-auth with tanstack start, I tried to use the best practices and the latest versions of every package included https://github.com/aliallaoua/better-auth/
GitHub
GitHub - aliallaoua/better-auth
Contribute to aliallaoua/better-auth development by creating an account on GitHub.

Did you find this page helpful?