Skip to content

Commit 880a5ba

Browse files
committed
move remaining uses
1 parent 0e94b82 commit 880a5ba

7 files changed

Lines changed: 17 additions & 39 deletions

File tree

apps/sim/app/api/billing/portal/route.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { and, eq } from 'drizzle-orm'
44
import { type NextRequest, NextResponse } from 'next/server'
55
import { getSession } from '@/lib/auth'
66
import { requireStripeClient } from '@/lib/billing/stripe-client'
7-
import { env } from '@/lib/env'
87
import { createLogger } from '@/lib/logs/console/logger'
8+
import { getBaseUrl } from '@/lib/urls/utils'
99

1010
const logger = createLogger('BillingPortal')
1111

@@ -21,8 +21,7 @@ export async function POST(request: NextRequest) {
2121
const context: 'user' | 'organization' =
2222
body?.context === 'organization' ? 'organization' : 'user'
2323
const organizationId: string | undefined = body?.organizationId || undefined
24-
const returnUrl: string =
25-
body?.returnUrl || `${env.NEXT_PUBLIC_APP_URL}/workspace?billing=updated`
24+
const returnUrl: string = body?.returnUrl || `${getBaseUrl()}/workspace?billing=updated`
2625

2726
const stripe = requireStripeClient()
2827

apps/sim/app/api/organizations/[id]/invitations/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import {
2323
} from '@/lib/billing/validation/seat-management'
2424
import { sendEmail } from '@/lib/email/mailer'
2525
import { quickValidateEmail } from '@/lib/email/validation'
26-
import { env } from '@/lib/env'
2726
import { createLogger } from '@/lib/logs/console/logger'
2827
import { hasWorkspaceAdminAccess } from '@/lib/permissions/utils'
28+
import { getBaseUrl } from '@/lib/urls/utils'
2929

3030
const logger = createLogger('OrganizationInvitations')
3131

@@ -339,7 +339,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
339339
organizationEntry[0]?.name || 'organization',
340340
role,
341341
workspaceInvitationsWithNames,
342-
`${env.NEXT_PUBLIC_APP_URL}/invite/${orgInvitation.id}`
342+
`${getBaseUrl()}/invite/${orgInvitation.id}`
343343
)
344344

345345
emailResult = await sendEmail({
@@ -352,7 +352,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
352352
const emailHtml = await renderInvitationEmail(
353353
inviter[0]?.name || 'Someone',
354354
organizationEntry[0]?.name || 'organization',
355-
`${env.NEXT_PUBLIC_APP_URL}/invite/${orgInvitation.id}`,
355+
`${getBaseUrl()}/invite/${orgInvitation.id}`,
356356
email
357357
)
358358

apps/sim/app/api/organizations/[id]/members/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { getUserUsageData } from '@/lib/billing/core/usage'
99
import { validateSeatAvailability } from '@/lib/billing/validation/seat-management'
1010
import { sendEmail } from '@/lib/email/mailer'
1111
import { quickValidateEmail } from '@/lib/email/validation'
12-
import { env } from '@/lib/env'
1312
import { createLogger } from '@/lib/logs/console/logger'
13+
import { getBaseUrl } from '@/lib/urls/utils'
1414

1515
const logger = createLogger('OrganizationMembersAPI')
1616

@@ -260,7 +260,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
260260
const emailHtml = await renderInvitationEmail(
261261
inviter[0]?.name || 'Someone',
262262
organizationEntry[0]?.name || 'organization',
263-
`${env.NEXT_PUBLIC_APP_URL}/invite/organization?id=${invitationId}`,
263+
`${getBaseUrl()}/invite/organization?id=${invitationId}`,
264264
normalizedEmail
265265
)
266266

apps/sim/app/api/webhooks/[id]/route.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { webhook, workflow } from '@sim/db/schema'
33
import { eq } from 'drizzle-orm'
44
import { type NextRequest, NextResponse } from 'next/server'
55
import { getSession } from '@/lib/auth'
6-
import { env } from '@/lib/env'
76
import { createLogger } from '@/lib/logs/console/logger'
87
import { getUserEntityPermissions } from '@/lib/permissions/utils'
8+
import { getBaseUrl } from '@/lib/urls/utils'
99
import { generateRequestId } from '@/lib/utils'
1010
import { getOAuthToken } from '@/app/api/auth/oauth/utils'
1111

@@ -282,13 +282,7 @@ export async function DELETE(
282282

283283
if (!resolvedExternalId) {
284284
try {
285-
if (!env.NEXT_PUBLIC_APP_URL) {
286-
logger.error(
287-
`[${requestId}] NEXT_PUBLIC_APP_URL not configured, cannot match Airtable webhook`
288-
)
289-
throw new Error('NEXT_PUBLIC_APP_URL must be configured')
290-
}
291-
const expectedNotificationUrl = `${env.NEXT_PUBLIC_APP_URL}/api/webhooks/trigger/${foundWebhook.path}`
285+
const expectedNotificationUrl = `${getBaseUrl()}/api/webhooks/trigger/${foundWebhook.path}`
292286

293287
const listUrl = `https://api.airtable.com/v0/bases/${baseId}/webhooks`
294288
const listResp = await fetch(listUrl, {

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/sso/sso.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { Check, ChevronDown, Copy, Eye, EyeOff } from 'lucide-react'
55
import { Alert, AlertDescription, Button, Input, Label } from '@/components/ui'
66
import { Skeleton } from '@/components/ui/skeleton'
77
import { useSession } from '@/lib/auth-client'
8-
import { env } from '@/lib/env'
98
import { isBillingEnabled } from '@/lib/environment'
109
import { createLogger } from '@/lib/logs/console/logger'
10+
import { getBaseUrl } from '@/lib/urls/utils'
1111
import { cn } from '@/lib/utils'
1212
import { useOrganizationStore } from '@/stores/organization'
1313

@@ -441,7 +441,7 @@ export function SSO() {
441441
})
442442
}
443443

444-
const callbackUrl = `${env.NEXT_PUBLIC_APP_URL}/api/auth/sso/callback/${formData.providerId}`
444+
const callbackUrl = `${getBaseUrl()}/api/auth/sso/callback/${formData.providerId}`
445445

446446
const copyCallback = async () => {
447447
try {
@@ -551,14 +551,14 @@ export function SSO() {
551551
<div className='relative mt-2'>
552552
<Input
553553
readOnly
554-
value={`${env.NEXT_PUBLIC_APP_URL}/api/auth/sso/callback/${provider.providerId}`}
554+
value={`${getBaseUrl()}/api/auth/sso/callback/${provider.providerId}`}
555555
className='h-9 w-full cursor-text pr-10 font-mono text-xs focus-visible:ring-2 focus-visible:ring-primary/20'
556556
onClick={(e) => (e.target as HTMLInputElement).select()}
557557
/>
558558
<button
559559
type='button'
560560
onClick={() => {
561-
const url = `${env.NEXT_PUBLIC_APP_URL}/api/auth/sso/callback/${provider.providerId}`
561+
const url = `${getBaseUrl()}/api/auth/sso/callback/${provider.providerId}`
562562
navigator.clipboard.writeText(url)
563563
setCopied(true)
564564
setTimeout(() => setCopied(false), 1500)

apps/sim/lib/branding/metadata.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ export function generateBrandedMetadata(override: Partial<Metadata> = {}): Metad
4040
referrer: 'origin-when-cross-origin',
4141
creator: brand.name,
4242
publisher: brand.name,
43-
metadataBase: env.NEXT_PUBLIC_APP_URL
44-
? new URL(env.NEXT_PUBLIC_APP_URL)
45-
: new URL('https://sim.ai'),
43+
metadataBase: new URL(getBaseUrl()),
4644
alternates: {
4745
canonical: '/',
4846
languages: {

apps/sim/lib/webhooks/webhook-helpers.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { db } from '@sim/db'
22
import { webhook as webhookTable } from '@sim/db/schema'
33
import { eq } from 'drizzle-orm'
44
import type { NextRequest } from 'next/server'
5-
import { env } from '@/lib/env'
65
import { createLogger } from '@/lib/logs/console/logger'
6+
import { getBaseUrl } from '@/lib/urls/utils'
77
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
88

99
const teamsLogger = createLogger('TeamsSubscription')
@@ -72,13 +72,7 @@ export async function createTeamsSubscription(
7272

7373
// Build notification URL
7474
// Always use NEXT_PUBLIC_APP_URL to ensure Microsoft Graph can reach the public endpoint
75-
if (!env.NEXT_PUBLIC_APP_URL) {
76-
teamsLogger.error(
77-
`[${requestId}] NEXT_PUBLIC_APP_URL not configured, cannot create Teams subscription`
78-
)
79-
return false
80-
}
81-
const notificationUrl = `${env.NEXT_PUBLIC_APP_URL}/api/webhooks/trigger/${webhook.path}`
75+
const notificationUrl = `${getBaseUrl()}/api/webhooks/trigger/${webhook.path}`
8276

8377
// Subscribe to the specified chat
8478
const resource = `/chats/${chatId}/messages`
@@ -224,14 +218,7 @@ export async function createTelegramWebhook(
224218
return false
225219
}
226220

227-
if (!env.NEXT_PUBLIC_APP_URL) {
228-
telegramLogger.error(
229-
`[${requestId}] NEXT_PUBLIC_APP_URL not configured, cannot register Telegram webhook`
230-
)
231-
return false
232-
}
233-
234-
const notificationUrl = `${env.NEXT_PUBLIC_APP_URL}/api/webhooks/trigger/${webhook.path}`
221+
const notificationUrl = `${getBaseUrl()}/api/webhooks/trigger/${webhook.path}`
235222

236223
const telegramApiUrl = `https://api.telegram.org/bot${botToken}/setWebhook`
237224
const telegramResponse = await fetch(telegramApiUrl, {

0 commit comments

Comments
 (0)