Skip to content

Commit 7dc0a51

Browse files
committed
change auth.ts and make getBaseUrl() call not top level for emails
1 parent f048788 commit 7dc0a51

8 files changed

Lines changed: 37 additions & 43 deletions

apps/sim/components/emails/batch-invitation-email.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ interface BatchInvitationEmailProps {
3030
acceptUrl: string
3131
}
3232

33-
const baseUrl = getBaseUrl()
34-
3533
const getPermissionLabel = (permission: string) => {
3634
switch (permission) {
3735
case 'admin':
@@ -64,6 +62,7 @@ export const BatchInvitationEmail = ({
6462
acceptUrl,
6563
}: BatchInvitationEmailProps) => {
6664
const brand = getBrandConfig()
65+
const baseUrl = getBaseUrl()
6766
const hasWorkspaces = workspaceInvitations.length > 0
6867

6968
return (

apps/sim/components/emails/enterprise-subscription-email.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ interface EnterpriseSubscriptionEmailProps {
2424
createdDate?: Date
2525
}
2626

27-
const baseUrl = getBaseUrl()
28-
2927
export const EnterpriseSubscriptionEmail = ({
3028
userName = 'Valued User',
3129
userEmail = '',
32-
loginLink = `${baseUrl}/login`,
30+
loginLink,
3331
createdDate = new Date(),
3432
}: EnterpriseSubscriptionEmailProps) => {
3533
const brand = getBrandConfig()
34+
const baseUrl = getBaseUrl()
35+
const effectiveLoginLink = loginLink || `${baseUrl}/login`
3636

3737
return (
3838
<Html>
@@ -75,7 +75,7 @@ export const EnterpriseSubscriptionEmail = ({
7575
in and start exploring your new Enterprise features:
7676
</Text>
7777

78-
<Link href={loginLink} style={{ textDecoration: 'none' }}>
78+
<Link href={effectiveLoginLink} style={{ textDecoration: 'none' }}>
7979
<Text style={baseStyles.button}>Access Your Enterprise Account</Text>
8080
</Link>
8181

apps/sim/components/emails/help-confirmation-email.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ interface HelpConfirmationEmailProps {
2323
submittedDate?: Date
2424
}
2525

26-
const baseUrl = getBaseUrl()
27-
2826
const getTypeLabel = (type: string) => {
2927
switch (type) {
3028
case 'bug':
@@ -47,6 +45,7 @@ export const HelpConfirmationEmail = ({
4745
submittedDate = new Date(),
4846
}: HelpConfirmationEmailProps) => {
4947
const brand = getBrandConfig()
48+
const baseUrl = getBaseUrl()
5049
const typeLabel = getTypeLabel(type)
5150

5251
return (

apps/sim/components/emails/invitation-email.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ interface InvitationEmailProps {
2626
updatedDate?: Date
2727
}
2828

29-
const baseUrl = getBaseUrl()
30-
3129
const logger = createLogger('InvitationEmail')
3230

3331
export const InvitationEmail = ({
@@ -38,6 +36,7 @@ export const InvitationEmail = ({
3836
updatedDate = new Date(),
3937
}: InvitationEmailProps) => {
4038
const brand = getBrandConfig()
39+
const baseUrl = getBaseUrl()
4140

4241
// Extract invitation ID or token from inviteLink if present
4342
let enhancedLink = inviteLink

apps/sim/components/emails/otp-verification-email.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ interface OTPVerificationEmailProps {
2222
chatTitle?: string
2323
}
2424

25-
const baseUrl = getBaseUrl()
26-
2725
const getSubjectByType = (type: string, brandName: string, chatTitle?: string) => {
2826
switch (type) {
2927
case 'sign-in':
@@ -46,6 +44,7 @@ export const OTPVerificationEmail = ({
4644
chatTitle,
4745
}: OTPVerificationEmailProps) => {
4846
const brand = getBrandConfig()
47+
const baseUrl = getBaseUrl()
4948

5049
// Get a message based on the type
5150
const getMessage = () => {

apps/sim/components/emails/reset-password-email.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ interface ResetPasswordEmailProps {
2323
updatedDate?: Date
2424
}
2525

26-
const baseUrl = getBaseUrl()
27-
2826
export const ResetPasswordEmail = ({
2927
username = '',
3028
resetLink = '',
3129
updatedDate = new Date(),
3230
}: ResetPasswordEmailProps) => {
3331
const brand = getBrandConfig()
32+
const baseUrl = getBaseUrl()
3433

3534
return (
3635
<Html>

apps/sim/components/emails/workspace-invitation.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ interface WorkspaceInvitationEmailProps {
2525
invitationLink?: string
2626
}
2727

28-
const baseUrl = getBaseUrl()
29-
3028
export const WorkspaceInvitationEmail = ({
3129
workspaceName = 'Workspace',
3230
inviterName = 'Someone',
3331
invitationLink = '',
3432
}: WorkspaceInvitationEmailProps) => {
3533
const brand = getBrandConfig()
34+
const baseUrl = getBaseUrl()
3635

3736
// Extract token from the link to ensure we're using the correct format
3837
let enhancedLink = invitationLink

apps/sim/lib/auth.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if (validStripeKey) {
6262
export const auth = betterAuth({
6363
baseURL: getBaseUrl(),
6464
trustedOrigins: [
65-
env.NEXT_PUBLIC_APP_URL,
65+
getBaseUrl(),
6666
...(env.NEXT_PUBLIC_SOCKET_URL ? [env.NEXT_PUBLIC_SOCKET_URL] : []),
6767
].filter(Boolean),
6868
database: drizzleAdapter(db, {
@@ -319,7 +319,7 @@ export const auth = betterAuth({
319319
tokenUrl: 'https://github.com/login/oauth/access_token',
320320
userInfoUrl: 'https://api.github.com/user',
321321
scopes: ['user:email', 'repo', 'read:user', 'workflow'],
322-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/github-repo`,
322+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/github-repo`,
323323
getUserInfo: async (tokens) => {
324324
try {
325325
const profileResponse = await fetch('https://api.github.com/user', {
@@ -400,7 +400,7 @@ export const auth = betterAuth({
400400
'https://www.googleapis.com/auth/gmail.labels',
401401
],
402402
prompt: 'consent',
403-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/google-email`,
403+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/google-email`,
404404
},
405405
{
406406
providerId: 'google-calendar',
@@ -414,7 +414,7 @@ export const auth = betterAuth({
414414
'https://www.googleapis.com/auth/calendar',
415415
],
416416
prompt: 'consent',
417-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/google-calendar`,
417+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/google-calendar`,
418418
},
419419
{
420420
providerId: 'google-drive',
@@ -428,7 +428,7 @@ export const auth = betterAuth({
428428
'https://www.googleapis.com/auth/drive.file',
429429
],
430430
prompt: 'consent',
431-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/google-drive`,
431+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/google-drive`,
432432
},
433433
{
434434
providerId: 'google-docs',
@@ -442,7 +442,7 @@ export const auth = betterAuth({
442442
'https://www.googleapis.com/auth/drive.file',
443443
],
444444
prompt: 'consent',
445-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/google-docs`,
445+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/google-docs`,
446446
},
447447
{
448448
providerId: 'google-sheets',
@@ -456,7 +456,7 @@ export const auth = betterAuth({
456456
'https://www.googleapis.com/auth/drive.file',
457457
],
458458
prompt: 'consent',
459-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/google-sheets`,
459+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/google-sheets`,
460460
},
461461

462462
{
@@ -471,7 +471,7 @@ export const auth = betterAuth({
471471
'https://www.googleapis.com/auth/forms.responses.readonly',
472472
],
473473
prompt: 'consent',
474-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/google-forms`,
474+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/google-forms`,
475475
},
476476

477477
{
@@ -487,7 +487,7 @@ export const auth = betterAuth({
487487
'https://www.googleapis.com/auth/devstorage.read_only',
488488
],
489489
prompt: 'consent',
490-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/google-vault`,
490+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/google-vault`,
491491
},
492492

493493
{
@@ -517,7 +517,7 @@ export const auth = betterAuth({
517517
accessType: 'offline',
518518
authentication: 'basic',
519519
pkce: true,
520-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/microsoft-teams`,
520+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/microsoft-teams`,
521521
},
522522

523523
{
@@ -532,7 +532,7 @@ export const auth = betterAuth({
532532
accessType: 'offline',
533533
authentication: 'basic',
534534
pkce: true,
535-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/microsoft-excel`,
535+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/microsoft-excel`,
536536
},
537537
{
538538
providerId: 'microsoft-planner',
@@ -554,7 +554,7 @@ export const auth = betterAuth({
554554
accessType: 'offline',
555555
authentication: 'basic',
556556
pkce: true,
557-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/microsoft-planner`,
557+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/microsoft-planner`,
558558
},
559559

560560
{
@@ -578,7 +578,7 @@ export const auth = betterAuth({
578578
accessType: 'offline',
579579
authentication: 'basic',
580580
pkce: true,
581-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/outlook`,
581+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/outlook`,
582582
},
583583

584584
{
@@ -593,7 +593,7 @@ export const auth = betterAuth({
593593
accessType: 'offline',
594594
authentication: 'basic',
595595
pkce: true,
596-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/onedrive`,
596+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/onedrive`,
597597
},
598598

599599
{
@@ -616,7 +616,7 @@ export const auth = betterAuth({
616616
accessType: 'offline',
617617
authentication: 'basic',
618618
pkce: true,
619-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/sharepoint`,
619+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/sharepoint`,
620620
},
621621

622622
{
@@ -628,7 +628,7 @@ export const auth = betterAuth({
628628
userInfoUrl: 'https://dummy-not-used.wealthbox.com', // Dummy URL since no user info endpoint exists
629629
scopes: ['login', 'data'],
630630
responseType: 'code',
631-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/wealthbox`,
631+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/wealthbox`,
632632
getUserInfo: async (tokens) => {
633633
try {
634634
logger.info('Creating Wealthbox user profile from token data')
@@ -662,7 +662,7 @@ export const auth = betterAuth({
662662
scopes: ['database.read', 'database.write', 'projects.read'],
663663
responseType: 'code',
664664
pkce: true,
665-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/supabase`,
665+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/supabase`,
666666
getUserInfo: async (tokens) => {
667667
try {
668668
logger.info('Creating Supabase user profile from token data')
@@ -715,7 +715,7 @@ export const auth = betterAuth({
715715
responseType: 'code',
716716
prompt: 'consent',
717717
authentication: 'basic',
718-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/x`,
718+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/x`,
719719
getUserInfo: async (tokens) => {
720720
try {
721721
const response = await fetch(
@@ -774,7 +774,7 @@ export const auth = betterAuth({
774774
accessType: 'offline',
775775
authentication: 'basic',
776776
prompt: 'consent',
777-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/confluence`,
777+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/confluence`,
778778
getUserInfo: async (tokens) => {
779779
try {
780780
const response = await fetch('https://api.atlassian.com/me', {
@@ -824,7 +824,7 @@ export const auth = betterAuth({
824824
accessType: 'offline',
825825
authentication: 'basic',
826826
prompt: 'consent',
827-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/discord`,
827+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/discord`,
828828
getUserInfo: async (tokens) => {
829829
try {
830830
const response = await fetch('https://discord.com/api/users/@me', {
@@ -895,7 +895,7 @@ export const auth = betterAuth({
895895
accessType: 'offline',
896896
authentication: 'basic',
897897
prompt: 'consent',
898-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/jira`,
898+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/jira`,
899899
getUserInfo: async (tokens) => {
900900
try {
901901
const response = await fetch('https://api.atlassian.com/me', {
@@ -946,7 +946,7 @@ export const auth = betterAuth({
946946
accessType: 'offline',
947947
authentication: 'basic',
948948
prompt: 'consent',
949-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/airtable`,
949+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/airtable`,
950950
},
951951

952952
// Notion provider
@@ -963,7 +963,7 @@ export const auth = betterAuth({
963963
accessType: 'offline',
964964
authentication: 'basic',
965965
prompt: 'consent',
966-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/notion`,
966+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/notion`,
967967
getUserInfo: async (tokens) => {
968968
try {
969969
const response = await fetch('https://api.notion.com/v1/users/me', {
@@ -1013,7 +1013,7 @@ export const auth = betterAuth({
10131013
accessType: 'offline',
10141014
authentication: 'basic',
10151015
prompt: 'consent',
1016-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/reddit`,
1016+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/reddit`,
10171017
getUserInfo: async (tokens) => {
10181018
try {
10191019
const response = await fetch('https://oauth.reddit.com/api/v1/me', {
@@ -1058,7 +1058,7 @@ export const auth = betterAuth({
10581058
tokenUrl: 'https://api.linear.app/oauth/token',
10591059
scopes: ['read', 'write'],
10601060
responseType: 'code',
1061-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/linear`,
1061+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/linear`,
10621062
pkce: true,
10631063
prompt: 'consent',
10641064
accessType: 'offline',
@@ -1145,7 +1145,7 @@ export const auth = betterAuth({
11451145
responseType: 'code',
11461146
accessType: 'offline',
11471147
prompt: 'consent',
1148-
redirectURI: `${env.NEXT_PUBLIC_APP_URL}/api/auth/oauth2/callback/slack`,
1148+
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/slack`,
11491149
getUserInfo: async (tokens) => {
11501150
try {
11511151
logger.info('Creating Slack bot profile from token data')
@@ -1413,7 +1413,7 @@ export const auth = betterAuth({
14131413
try {
14141414
const { invitation, organization, inviter } = data
14151415

1416-
const inviteUrl = `${env.NEXT_PUBLIC_APP_URL}/invite/${invitation.id}`
1416+
const inviteUrl = `${getBaseUrl()}/invite/${invitation.id}`
14171417
const inviterName = inviter.user?.name || 'A team member'
14181418

14191419
const html = await renderInvitationEmail(

0 commit comments

Comments
 (0)