I'm new to this and struggling with better-auth. Redirects work fine for social logins (Google, GitHub), but not for email login. The server logs show the redirect happening correctly (like "User recognized, redirecting to /account/profile" with a 302 status and Location: /account/profile in the network tab), but the browser doesn't follow it for email login. Instead, I get an APIError with empty headers (headers: Headers {}). Is this a bug in better-auth? I'm using authClient.signIn.email with fetchOptions: { redirect: "follow" } in a Next.js app.
after: createAuthMiddleware(async (ctx) => { if (ctx.path === "/callback/:id" ctx.context.session; if (!session || !session.user) { return; } const role = session.user.role ? session.user.role.toUpperCase() : null; if (role === "ADMIN") { throw ctx.redirect("/admin/posts"); } else if (role === "USER") { throw ctx.redirect("/account/profile"); } else { throw ctx.redirect("/unauthorized"); } } }),