google successful signin redirect

my redirect uris are
http://localhost:3000/api/auth/callback/google
https://workers.dev/api/auth/callback/google

i am using nextjs for frontend and hono for backend
after successful auth i get redirected to https://workers.dev
i want to change this and redirect to localhost:3000 or any other frontend url
below is my backend code

// src/routes/auth.route.ts
import { Context, Hono } from "hono";
import { getAuth } from "../lib/auth"; // Adjust path as necessary for this file

const authRouter = new Hono();

authRouter.on(["POST", "GET"], "/*", async (c: Context) => {
  // The wildcard here becomes '/*' because 'authRouter' is already mounted at '/api/auth'
  console.log(`authRouter request: ${c.req.method} ${c.req.url}`);
  const auth = getAuth(c);
  const response = await auth.handler(c.req.raw);
  return response;
});

export default authRouter;

export function getAuth(c: Context) {
  const db = getDb(c);
  return betterAuth({
    emailAndPassword: { enabled: true },
    socialProviders: {
      google: {
        prompt: "select_account",
        clientId: c.env.GOOGLE_CLIENT_ID as string,
        clientSecret: c.env.GOOGLE_CLIENT_SECRET as string,
      },
    },
    database: drizzleAdapter(db, {
      provider: "pg", // or "mysql", "sqlite"
      schema: { ...schema },
    }),
    advanced: {
      defaultCookieAttributes: {
        sameSite: "none", // Correct
      },
      // Removed crossSubDomainCookies, as it's not applicable for different top-level domains.
      useSecureCookies: true, // Correct, implies secure: true for all cookies
    },
    trustedOrigins: [
      "http://localhost:3000",
    ],
  });
}
Build your next application with Cloudflare Workers
Build your next application with Cloudflare Workers
Was this page helpful?