This server side code worked on `^1.1.18`, but not anymore on `^1.2.0`.

This is how my Hono routes,
.post("signIn", zValidator("json", loginSchema), async (c) => {
const data = c.req.valid("json");
const { email, password } = data;

try {
const res = await auth.api.signInEmail({
header: c.req.raw.headers,
body: { email, password },
asResponse: true
});

const cookies = res.headers.get("set-cookie");
if (cookies) {
c.header("set-cookie", cookies);
}

return c.json({ success: true, message: `Success` }, 200);
} catch (error) {
const message = handleAuthError(error);
return c.json({ success: false, message }, 500);
}
})
.post("signIn", zValidator("json", loginSchema), async (c) => {
const data = c.req.valid("json");
const { email, password } = data;

try {
const res = await auth.api.signInEmail({
header: c.req.raw.headers,
body: { email, password },
asResponse: true
});

const cookies = res.headers.get("set-cookie");
if (cookies) {
c.header("set-cookie", cookies);
}

return c.json({ success: true, message: `Success` }, 200);
} catch (error) {
const message = handleAuthError(error);
return c.json({ success: false, message }, 500);
}
})
I filled fake email and password. Although I got this error log in terminal console:
2025-03-02T03:07:30.067Z ERROR [Better Auth]: Invalid password
2025-03-02T03:07:30.067Z ERROR [Better Auth]: Invalid password
I am getting
({ success: true, message: `Success` }, 200)
({ success: true, message: `Success` }, 200)
in my browser. I think there is a problem with try catch .
9 Replies
Sithu Khant
Sithu KhantOP2d ago
This is in the network tab
No description
Sithu Khant
Sithu KhantOP2d ago
I think I should get 500 ...any suggestion?
lonelyplanet
lonelyplanet2d ago
your using asResponse I believe thats the issue since when asResponse is set you can simple return the res object since it will be a Response object And when asResponse it would not want to reject the promise instead it returns a error Response
Sithu Khant
Sithu KhantOP9h ago
If I do that, it doesn't work If I do that, I don't be able to get res.headers from it
lonelyplanet
lonelyplanet8h ago
Just get the session token manually delete as Response use session.token from the result of the call and set that as your cookie
Sithu Khant
Sithu KhantOP7h ago
How can I get?
lonelyplanet
lonelyplanet5h ago
.
Sithu Khant
Sithu KhantOP4h ago
I still don't get it could you please give an example?
lonelyplanet
lonelyplanet4h ago
const res = await auth.api.signInEmail({
header: c.req.raw.headers,
body: { email, password },
});

const token = res?.session?.token;
const res = await auth.api.signInEmail({
header: c.req.raw.headers,
body: { email, password },
});

const token = res?.session?.token;

Did you find this page helpful?