fix: use custom domain for auth baseURL in production
VERCEL_URL returns deployment URL (tpmjs-xxx.vercel.app) not custom domain. This was causing session cookies to be set for wrong domain. Now prioritizes BETTER_AUTH_URL, then checks VERCEL_ENV=production to use tpmjs.com.
This commit is contained in:
parent
1c9a328929
commit
4451eddc91
2 changed files with 7 additions and 2 deletions
2
apps/web/next-env.d.ts
vendored
2
apps/web/next-env.d.ts
vendored
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
import "./.next/types/routes.d.ts";
|
||||
import "./.next/dev/types/routes.d.ts";
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
|
|
|
|||
|
|
@ -3,9 +3,14 @@ import { betterAuth } from 'better-auth';
|
|||
import { prismaAdapter } from 'better-auth/adapters/prisma';
|
||||
import { sendVerificationEmail } from './email';
|
||||
|
||||
// Determine base URL: use env var, or Vercel URL, or default to production
|
||||
// Determine base URL for auth - MUST match the domain users are browsing on
|
||||
// VERCEL_URL is the deployment URL (e.g., tpmjs-xxx.vercel.app), not the custom domain
|
||||
// So we prioritize BETTER_AUTH_URL or fall back to the production domain
|
||||
const getBaseURL = () => {
|
||||
if (process.env.BETTER_AUTH_URL) return process.env.BETTER_AUTH_URL;
|
||||
// In production, always use the custom domain, not VERCEL_URL
|
||||
if (process.env.VERCEL_ENV === 'production') return 'https://tpmjs.com';
|
||||
// For preview deployments, use the Vercel URL
|
||||
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`;
|
||||
return 'https://tpmjs.com';
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue