Options. See InitGoogleAuthOptions.
Object with GET — export as your route's GET handler.
// app/api/(auth)/google/route.ts
import { initGoogleAuth } from "naystack/auth";
export const { GET } = initGoogleAuth({
getUserIdFromEmail: async (googleUser) => {
// Find or create user by Google email
const user = await findOrCreateUserByEmail(googleUser.email!);
return user?.id ?? null;
},
redirectURL: "/dashboard",
errorRedirectURL: "/login",
});
Initializes Google OAuth. Returns a GET handler that initiates the OAuth flow (redirects to Google) and handles the callback (exchanges code for tokens, calls
getUserIdFromEmail, sets refresh cookie).Mount the GET handler on your Google auth route (e.g.
app/api/(auth)/google/route.ts).Requires env vars:
GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET,NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT.