Vercel preview deployments have dynamic URLs (e.g., my-app-git-feature-username.vercel.app) but OAuth providers require static redirect URIs. This proxy acts as a bridge.
https://oauth.agens.io/start/google?target=https://my-app-git-feature-me.vercel.apphttps://oauth.agens.io/callback/googlehttps://my-app-git-feature-me.vercel.app/api/auth/callback/google
// Redirect to OAuth proxy instead of direct OAuth
const targetUrl = encodeURIComponent(window.location.origin);
window.location.href = "https://oauth.agens.io/start/google?target=" + targetUrl;
https://oauth.agens.io/callback/google
https://oauth.agens.io/callback/github
Your app needs an endpoint at /api/auth/callback/:provider that:
code and state query parameterscode for access token with OAuth provider// pages/api/auth/[...nextauth].js or app/api/auth/[...nextauth]/route.js
import GoogleProvider from "next-auth/providers/google"
export const authOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
})
]
}// Instead of: signIn('google')
// Use:
const targetUrl = encodeURIComponent(window.location.origin);
window.location.href = "https://oauth.agens.io/start/google?target=" + targetUrl;PUBLIC_URL=https://oauth.agens.ioALLOWED_HOSTS=^https://.*\.vercel\.app$GOOGLE_CLIENT_ID=your_google_client_idGITHUB_CLIENT_ID=your_github_client_idRATE_LIMIT_MAX=10 (requests per window)RATE_LIMIT_WINDOW_MINUTES=15 (window duration in minutes)/api/auth/callback/:provider endpoint