Skip to content

Commit 43d6215

Browse files
committed
make publicUrl and sandboxMode env vars, installationId env or generated, inc expiration time
1 parent 1743066 commit 43d6215

File tree

19 files changed

+23
-138
lines changed

19 files changed

+23
-138
lines changed

actions/appSettings.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { type z } from 'zod';
66
import { env } from '~/env';
77
import { DEFAULT_APP_SETTINGS } from '~/fresco.config';
88
import { safeRevalidateTag } from '~/lib/cache';
9-
import { getAppSetting } from '~/queries/appSettings';
109
import { appSettingsSchema } from '~/schemas/appSettings';
1110
import { createEnvironmentFormSchema } from '~/schemas/environment';
1211
import { requireApiAuth } from '~/utils/auth';
@@ -77,37 +76,19 @@ export async function storeEnvironment(formData: unknown) {
7776
}
7877

7978
try {
80-
const { uploadThingToken, publicUrl, installationId } = parsedFormData.data;
79+
const { uploadThingToken } = parsedFormData.data;
8180

8281
const data = [
8382
{ key: 'uploadThingToken', value: uploadThingToken },
84-
{ key: 'sandboxMode', value: 'false' },
8583
{ key: 'disableAnalytics', value: 'false' },
8684
];
8785

88-
// Add optional env variables if they were provided
89-
if (publicUrl) {
90-
data.push({ key: 'publicUrl', value: publicUrl });
91-
}
92-
93-
if (installationId) {
94-
await setAppSetting('installationId', installationId);
95-
} else {
96-
// check for existing installationId in db (from env)
97-
const existingInstallationId = await getAppSetting('installationId');
98-
if (!existingInstallationId) {
99-
// no env or installation id provided, generate one
100-
await setAppSetting('installationId', createId());
101-
}
102-
}
103-
10486
// insert the rest of the env variables
10587
await prisma.appSettings.createManyAndReturn({
10688
data,
10789
skipDuplicates: true,
10890
});
10991
safeRevalidateTag(`appSettings-uploadThingToken`);
110-
safeRevalidateTag(`appSettings-sandboxMode`);
11192
safeRevalidateTag(`appSettings-disableAnalytics`);
11293

11394
return { success: true };
@@ -127,7 +108,8 @@ export async function initializeWithDefaults() {
127108
})) as { key: InitializeKeys; value: string }[];
128109

129110
// add installation id if there is one in the env
130-
const installationId = env.INSTALLATION_ID;
111+
// if not, generate one
112+
const installationId = env.INSTALLATION_ID ?? createId();
131113
if (installationId) {
132114
data.push({
133115
key: 'installationId',

app/(blobs)/(setup)/_components/EnvironmentForm.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import { Input } from '~/components/ui/Input';
66
import useZodForm from '~/hooks/useZodForm';
77
import { createEnvironmentSchema } from '~/schemas/environment';
88

9-
export const EnvironmentForm = ({
10-
installationId,
11-
}: {
12-
installationId: string | null;
13-
}) => {
9+
export const EnvironmentForm = () => {
1410
const {
1511
register,
1612
formState: { errors, isValid },
@@ -30,27 +26,6 @@ export const EnvironmentForm = ({
3026
{...register('uploadThingToken')}
3127
/>
3228
</div>
33-
<div className="mb-6 flex flex-wrap">
34-
<Input
35-
label="Public URL"
36-
hint="When using advanced deployment, this is required. Set to the domain name of your app."
37-
type="text"
38-
error={errors.publicUrl?.message}
39-
{...register('publicUrl')}
40-
/>
41-
</div>
42-
{!installationId && (
43-
<div className="mb-6 flex flex-wrap">
44-
<Input
45-
label="Installation Id"
46-
hint="An optional unique identifier for your app, used for analytics. This will be generated automatically if not set."
47-
type="text"
48-
placeholder="installation-id..."
49-
error={errors.installationId?.message}
50-
{...register('installationId')}
51-
/>
52-
</div>
53-
)}
5429
<div className="flex flex-wrap">
5530
<Button disabled={!isValid} type="submit">
5631
Submit

app/(blobs)/(setup)/_components/OnboardSteps/ConfigureEnvironment.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import Heading from '~/components/ui/typography/Heading';
22
import Paragraph from '~/components/ui/typography/Paragraph';
33
import { EnvironmentForm } from '../EnvironmentForm';
44

5-
function ConfigureEnvironment({
6-
installationId,
7-
}: {
8-
installationId: string | null;
9-
}) {
5+
function ConfigureEnvironment() {
106
return (
117
<div className="w-[30rem]">
128
<div className="mb-4">
@@ -15,7 +11,7 @@ function ConfigureEnvironment({
1511
Next, configure your environment. Follow the steps in the deployment
1612
guide to set these values.
1713
</Paragraph>
18-
<EnvironmentForm installationId={installationId} />
14+
<EnvironmentForm />
1915
</div>
2016
</div>
2117
);

app/(blobs)/(setup)/_components/OnboardSteps/DeploymentSettings.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import { Button } from '~/components/ui/Button';
44
import Heading from '~/components/ui/typography/Heading';
55
import Paragraph from '~/components/ui/typography/Paragraph';
66
import DisableAnalyticsSwitch from '../DisableAnalyticsSwitch';
7-
import SandboxModeSwitch from '../SandboxModeSwitch';
87

98
function DeploymentSettings({
10-
sandboxMode,
119
disableAnalytics,
1210
}: {
13-
sandboxMode: boolean;
1411
disableAnalytics: boolean;
1512
}) {
1613
const [currentStep, setCurrentStep] = useQueryState(
@@ -31,15 +28,6 @@ function DeploymentSettings({
3128
</Paragraph>
3229
</div>
3330
<div className="mb-6 flex flex-col gap-2">
34-
<SettingsSection
35-
heading="Sandbox Mode"
36-
controlArea={<SandboxModeSwitch sandboxMode={sandboxMode} />}
37-
>
38-
<Paragraph>
39-
If enabled, the app will use the sandbox mode, which disables
40-
resetting the database and other features.
41-
</Paragraph>
42-
</SettingsSection>
4331
<SettingsSection
4432
heading="Disable Analytics"
4533
controlArea={

app/(blobs)/(setup)/_components/SandboxCredentials.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { KeyRound } from 'lucide-react';
22
import { Alert, AlertDescription, AlertTitle } from '~/components/ui/Alert';
3+
import { env } from '~/env';
34

45
export default function SandboxCredentials() {
6+
if (!env.SANDBOX_MODE) return null;
57
return (
68
<Alert variant="info">
79
<KeyRound className="h-4 w-4" />

app/(blobs)/(setup)/_components/SandboxModeSwitch.tsx

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/(blobs)/(setup)/setup/Setup.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ export default function Setup({
2525
hasAuth,
2626
allowAnonymousRecruitment,
2727
limitInterviews,
28-
installationId,
29-
sandboxMode,
3028
disableAnalytics,
3129
hasUploadThingToken,
3230
} = use(setupDataPromise);
@@ -54,7 +52,6 @@ export default function Setup({
5452
if (hasAuth && step > 2) {
5553
if (
5654
!hasUploadThingToken ||
57-
sandboxMode === null ||
5855
disableAnalytics === null ||
5956
allowAnonymousRecruitment === null ||
6057
limitInterviews === null
@@ -68,7 +65,6 @@ export default function Setup({
6865
step,
6966
setStep,
7067
hasUploadThingToken,
71-
sandboxMode,
7268
disableAnalytics,
7369
allowAnonymousRecruitment,
7470
limitInterviews,
@@ -79,12 +75,9 @@ export default function Setup({
7975
<OnboardSteps />
8076
<div className={mainClasses}>
8177
{step === 1 && <CreateAccount />}
82-
{step === 2 && <ConfigureEnvironment installationId={installationId} />}
83-
{step === 3 && sandboxMode !== null && disableAnalytics !== null && (
84-
<DeploymentSettings
85-
sandboxMode={sandboxMode}
86-
disableAnalytics={disableAnalytics}
87-
/>
78+
{step === 2 && <ConfigureEnvironment />}
79+
{step === 3 && disableAnalytics !== null && (
80+
<DeploymentSettings disableAnalytics={disableAnalytics} />
8881
)}
8982
{step === 4 && <UploadProtocol />}
9083
{step === 5 &&

app/(blobs)/(setup)/setup/page.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ async function getSetupData() {
2020
prisma.participant.count(),
2121
]);
2222

23-
const sandboxMode = await getAppSetting('sandboxMode');
2423
const disableAnalytics = await getAppSetting('disableAnalytics');
25-
const installationId = await getAppSetting('installationId');
2624
const uploadThingToken = await getAppSetting('uploadThingToken');
2725

2826
return {
@@ -31,9 +29,7 @@ async function getSetupData() {
3129
limitInterviews,
3230
hasProtocol: otherData[0] > 0,
3331
hasParticipants: otherData[1] > 0,
34-
sandboxMode,
3532
disableAnalytics,
36-
installationId,
3733
hasUploadThingToken: !!uploadThingToken,
3834
};
3935
}

app/(blobs)/(setup)/signin/page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { redirect } from 'next/navigation';
22
import { containerClasses } from '~/components/ContainerClasses';
3-
import { getAppSetting } from '~/queries/appSettings';
43
import { getServerSession } from '~/utils/auth';
54
import { cn } from '~/utils/shadcn';
65
import SandboxCredentials from '../_components/SandboxCredentials';
@@ -15,7 +14,6 @@ export const dynamic = 'force-dynamic';
1514

1615
export default async function Page() {
1716
const session = await getServerSession();
18-
const sandboxMode = await getAppSetting('sandboxMode');
1917

2018
if (session) {
2119
// If the user is already signed in, redirect to the dashboard
@@ -25,7 +23,7 @@ export default async function Page() {
2523
return (
2624
<div className={cn(containerClasses, 'w-[25rem]')}>
2725
<h1 className="mb-6 text-2xl font-bold">Sign In To Fresco</h1>
28-
{sandboxMode === true && <SandboxCredentials />}
26+
<SandboxCredentials />
2927
<SignInForm />
3028
</div>
3129
);

app/(interview)/onboard/[protocolId]/route.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { cookies } from 'next/headers';
22
import { NextResponse, type NextRequest } from 'next/server';
33
import { createInterview } from '~/actions/interviews';
4+
import { env } from '~/env';
45
import trackEvent from '~/lib/analytics';
56
import { getAppSetting } from '~/queries/appSettings';
67

@@ -12,13 +13,11 @@ const handler = async (
1213
) => {
1314
const protocolId = params.protocolId; // From route segment
1415

15-
const publicUrl = await getAppSetting('publicUrl');
16-
1716
// when deployed via docker `req.url` and `req.nextUrl`
1817
// shows Docker Container ID instead of real host
1918
// issue: https://github.com/vercel/next.js/issues/65568
20-
// workaround: use `publicUrl` to get the correct url
21-
const url = new URL(publicUrl ?? req.nextUrl.clone());
19+
// workaround: use `env.PUBLIC_URL` to get the correct url
20+
const url = new URL(env.PUBLIC_URL ?? req.nextUrl.clone());
2221

2322
// If no protocol ID is provided, redirect to the error page.
2423
if (!protocolId || protocolId === 'undefined') {

0 commit comments

Comments
 (0)