Skip to content

Commit d6212de

Browse files
fix(invite): Fix localhost being used in invite links and in UI (#764)
* 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> * chore: update example URLs and add changelog entry - Changed example URL from example.sourcebot.dev to sourcebot.example.com - Added changelog entry for PR #764 Co-authored-by: michael <michael@sourcebot.dev> * move getBaseUrl to server component --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 2c9a70e commit d6212de

File tree

7 files changed

+29
-19
lines changed

7 files changed

+29
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Bumped Node.js version to v24. [#753](https://github.com/sourcebot-dev/sourcebot/pull/753)
1313

1414
### Fixes
15+
- Fixed hardcoded localhost URLs in org URL and invite links by using AUTH_URL as fallback. [#764](https://github.com/sourcebot-dev/sourcebot/pull/764)
1516
- Fix autocomplete when repo includes default port [#762](https://github.com/sourcebot-dev/sourcebot/pull/762)
1617
- Fixed "Repository not found for file: x" error when searching in orphaned shards. [#761](https://github.com/sourcebot-dev/sourcebot/pull/761)
1718

packages/web/src/app/components/organizationAccessSettings.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { createInviteLink, getBaseUrl } from "@/lib/utils"
1+
import { createInviteLink } from "@/lib/utils"
2+
import { getBaseUrl } from "@/lib/utils.server"
23
import { AnonymousAccessToggle } from "./anonymousAccessToggle"
34
import { OrganizationAccessSettingsWrapper } from "./organizationAccessSettingsWrapper"
45
import { getOrgFromDomain } from "@/data/org"

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://sourcebot.example.com/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://sourcebot.example.com',
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://sourcebot.example.com',
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;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { env } from "@sourcebot/shared";
2+
3+
/**
4+
* Gets the base URL from Next.js headers, falling back to AUTH_URL environment variable
5+
* @param headersList The headers from Next.js headers() function
6+
* @returns The base URL (e.g., "https://example.com")
7+
*/
8+
export const getBaseUrl = (headersList: Headers): string => {
9+
const host = headersList.get('host');
10+
const protocol = headersList.get('x-forwarded-proto');
11+
12+
// If we have both host and protocol from headers, use them
13+
if (host && protocol) {
14+
return `${protocol}://${host}`;
15+
}
16+
17+
// Fall back to AUTH_URL environment variable
18+
return env.AUTH_URL;
19+
}

packages/web/src/lib/utils.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@ export function cn(...inputs: ClassValue[]) {
2525
return twMerge(clsx(inputs))
2626
}
2727

28-
/**
29-
* Gets the base URL from Next.js headers
30-
* @param headersList The headers from Next.js headers() function
31-
* @returns The base URL (e.g., "https://example.com")
32-
*/
33-
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}`;
37-
}
38-
3928
/**
4029
* Creates an invite link URL from the base URL and invite ID
4130
* @param baseUrl The base URL of the application

0 commit comments

Comments
 (0)