To prevent OAuth libraries from constructing localhost callback URLs, you must explicitly set the base URL to match your Portless domain.
NextAuth / Auth.js
Set NEXTAUTH_URL (or AUTH_URL for Auth.js v5) in your environment:
NEXTAUTH_URL=https://myapp.dev
Passport.js
Set the callbackURL in your strategy using a BASE_URL environment variable:
new GoogleStrategy({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.BASE_URL + "/auth/google/callback",
});
Set BASE_URL=https://myapp.dev in your .env.
Generic / Manual
Use the PORTLESS_URL environment variable which is automatically injected by Portless into the child process:
const baseUrl = process.env.PORTLESS_URL || "http://localhost:3000";
const callbackUrl = `${baseUrl}/auth/callback`;