fix: auto-detect baseURL for Better Auth in production
This commit is contained in:
parent
0a06a15789
commit
e04d92e439
1 changed files with 8 additions and 1 deletions
|
|
@ -3,9 +3,16 @@ 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
|
||||
const getBaseURL = () => {
|
||||
if (process.env.BETTER_AUTH_URL) return process.env.BETTER_AUTH_URL;
|
||||
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`;
|
||||
return 'https://tpmjs.com';
|
||||
};
|
||||
|
||||
export const auth = betterAuth({
|
||||
secret: process.env.BETTER_AUTH_SECRET,
|
||||
baseURL: process.env.BETTER_AUTH_URL,
|
||||
baseURL: getBaseURL(),
|
||||
database: prismaAdapter(prisma, {
|
||||
provider: 'postgresql',
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue