ctx.redirect not working?

When the user is signing in, I want to check for something in the additional fields and redirect based on that. But even this simple redirect script doesn't seem to work.

export const auth = betterAuth({
  // other config
  hooks: {
    after: createAuthMiddleware(async (ctx) => {
      if (ctx.path.startsWith('/sign-in')) {
        console.log("Redirecting to /test");
        throw ctx.redirect('/test');
      }
    }),
  }
})
Was this page helpful?