Skip to content

Commit 22939af

Browse files
cursoragentmsukkari
andcommitted
fix: use AUTH_URL as fallback instead of hardcoded localhost in getBaseUrl
- Updated getBaseUrl() in utils.ts to fall back to AUTH_URL environment variable instead of hardcoded 'localhost:3000' when headers are not available - Updated email preview props in inviteUserEmail.tsx, joinRequestApprovedEmail.tsx, and joinRequestSubmittedEmail.tsx to use example.sourcebot.dev instead of localhost URLs This fixes the issue where org URL and invite links were being generated with localhost when the host/protocol headers were not available. Co-authored-by: michael <michael@sourcebot.dev>
1 parent 2c9a70e commit 22939af

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

packages/web/src/emails/inviteUserEmail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ InviteUserEmail.PreviewProps = {
138138
},
139139
orgName: 'Enigma',
140140
orgImageUrl: SOURCEBOT_PLACEHOLDER_AVATAR_URL,
141-
inviteLink: 'https://localhost:3000/redeem?invite_id=1234',
141+
inviteLink: 'https://example.sourcebot.dev/redeem?invite_id=1234',
142142
} satisfies InviteUserEmailProps;
143143

144144
export default InviteUserEmail;

packages/web/src/emails/joinRequestApprovedEmail.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Text,
1414
} from '@react-email/components';
1515
import { EmailFooter } from './emailFooter';
16-
import { SOURCEBOT_LOGO_LIGHT_LARGE_URL } from './constants';
16+
import { SOURCEBOT_LOGO_LIGHT_LARGE_URL, SOURCEBOT_PLACEHOLDER_AVATAR_URL } from './constants';
1717

1818
interface JoinRequestApprovedEmailProps {
1919
baseUrl: string;
@@ -83,11 +83,11 @@ export const JoinRequestApprovedEmail = ({
8383
};
8484

8585
JoinRequestApprovedEmail.PreviewProps = {
86-
baseUrl: 'http://localhost:3000',
86+
baseUrl: 'https://example.sourcebot.dev',
8787
user: {
8888
name: 'Alan Turing',
8989
email: 'alan.turing@example.com',
90-
avatarUrl: `http://localhost:3000/placeholder_avatar.png`,
90+
avatarUrl: SOURCEBOT_PLACEHOLDER_AVATAR_URL,
9191
},
9292
orgName: 'Enigma',
9393
orgDomain: '~',

packages/web/src/emails/joinRequestSubmittedEmail.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ const RequestorInfo = ({ email, name }: { email: string, name?: string }) => {
127127
}
128128

129129
JoinRequestSubmittedEmail.PreviewProps = {
130-
baseUrl: 'http://localhost:3000',
130+
baseUrl: 'https://example.sourcebot.dev',
131131
requestor: {
132132
name: 'Alan Turing',
133133
email: 'alan.turing@example.com',
134-
avatarUrl: `http://localhost:3000/placeholder_avatar.png`,
134+
avatarUrl: SOURCEBOT_PLACEHOLDER_AVATAR_URL,
135135
},
136136
orgName: 'Enigma',
137137
orgDomain: '~',
138-
orgImageUrl: `http://localhost:3000/placeholder_avatar.png`,
138+
orgImageUrl: SOURCEBOT_PLACEHOLDER_AVATAR_URL,
139139
} satisfies JoinRequestSubmittedEmailProps;
140140

141141
export default JoinRequestSubmittedEmail;

packages/web/src/lib/utils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,28 @@ import { ConnectionType, Org } from "@sourcebot/db";
2020
import { OrgMetadata, orgMetadataSchema } from "@/types";
2121
import { SINGLE_TENANT_ORG_DOMAIN } from "./constants";
2222
import { CodeHostType } from "@sourcebot/db";
23+
import { env } from "@sourcebot/shared";
2324

2425
export function cn(...inputs: ClassValue[]) {
2526
return twMerge(clsx(inputs))
2627
}
2728

2829
/**
29-
* Gets the base URL from Next.js headers
30+
* Gets the base URL from Next.js headers, falling back to AUTH_URL environment variable
3031
* @param headersList The headers from Next.js headers() function
3132
* @returns The base URL (e.g., "https://example.com")
3233
*/
3334
export const getBaseUrl = (headersList: Headers): string => {
34-
const host = headersList.get('host') || 'localhost:3000';
35-
const protocol = headersList.get('x-forwarded-proto') || 'http';
36-
return `${protocol}://${host}`;
35+
const host = headersList.get('host');
36+
const protocol = headersList.get('x-forwarded-proto');
37+
38+
// If we have both host and protocol from headers, use them
39+
if (host && protocol) {
40+
return `${protocol}://${host}`;
41+
}
42+
43+
// Fall back to AUTH_URL environment variable
44+
return env.AUTH_URL;
3745
}
3846

3947
/**

0 commit comments

Comments
 (0)