I'm using a client-side React island to call a Better Auth signInEmail function via an Astro Action. The sign-in succeeds, but cookies (e.g. session) are not being set.
Here’s the defineAction I'm using:
signInWithEmail: defineAction({
accept: 'json',
input: signInSchema,
handler: async ({ email, password }, context) => {
try {
const res = await auth.api.signInEmail({
body: { email, password, rememberMe: true },
headers: context.request.headers,
});
return { success: true, message: 'Sign in success' };
} catch (error) {
throw new ActionError({ code: 'BAD_REQUEST', message: 'Sign in failed' });
}
},
});
And this is how I’m calling it from the React island:
async function onSubmit(payload: SignInSchema) {
form.clearErrors();
setError('');
startTransition(async () => {
const { data, error } = await actions.authAction.signInWithEmail(payload);
if (isInputError(error)) {
Object.entries(error.fields).forEach(([field, messages]) => {
form.setError(field as any, {
type: 'manual',
message: messages[0],
});
});
} else if (error) {
setError(error.message);
}
});
}
How can I make sure the cookies (set-cookie header) are properly persisted in this setup?