From 37ba263d1042c7c6d3e4283a13f1ab202906eb76 Mon Sep 17 00:00:00 2001 From: Zai Shi Date: Mon, 4 Mar 2024 13:57:16 +0800 Subject: [PATCH] fixed onboarding --- .../[projectId]/onboarding-dialog.tsx | 62 ++++++++++++------- .../(main)/(protected)/projects/header.tsx | 14 ++--- .../(protected)/projects/page-client.tsx | 1 + 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/packages/stack-server/src/app/(main)/(protected)/projects/[projectId]/onboarding-dialog.tsx b/packages/stack-server/src/app/(main)/(protected)/projects/[projectId]/onboarding-dialog.tsx index ad64ffe0c..b1d83b2ad 100644 --- a/packages/stack-server/src/app/(main)/(protected)/projects/[projectId]/onboarding-dialog.tsx +++ b/packages/stack-server/src/app/(main)/(protected)/projects/[projectId]/onboarding-dialog.tsx @@ -2,22 +2,22 @@ import { Dialog } from "@/components/dialog"; import { use, useId, useRef, useState } from "react"; import { useStrictMemo } from "stack-shared/src/hooks/use-strict-memo"; import { useAdminApp } from "./useAdminInterface"; -import { Stack } from "@mui/joy"; +import { Box, Stack, Typography } from "@mui/joy"; import { Paragraph } from "@/components/paragraph"; import Link from "next/link"; export function OnboardingDialog() { - return null; // TODO: Enable after fixing the "root exit" issue + const called = useRef(false); const formId = useId(); const stackAdminApp = useAdminApp(); - const [open, setOpen] = useState(false); + const [open, setOpen] = useState(true); - const projectPromise = useStrictMemo(() => { - return stackAdminApp.getProject(); - }, []); - const project = use(projectPromise); + const dataPromis = useStrictMemo(async () => { + if (called.current) { + return; + } + called.current = true; - const apiKeyPromise = useStrictMemo(async () => { const apiKeySets = await stackAdminApp.listApiKeySets(); if (apiKeySets.length > 0) { return; @@ -25,28 +25,33 @@ export function OnboardingDialog() { setOpen(true); - return await stackAdminApp.createApiKeySet({ - hasPublishableClientKey: true, - hasSecretServerKey: true, - hasSuperSecretAdminKey: false, - expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 200), // 200 years, effectively never - description: 'Onboarding' - }); + return await Promise.all([ + stackAdminApp.createApiKeySet({ + hasPublishableClientKey: true, + hasSecretServerKey: true, + hasSuperSecretAdminKey: false, + expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 200), // 200 years, effectively never + description: 'Onboarding' + }), + stackAdminApp.getProject() + ]); }, []); - const apiKey = use(apiKeyPromise); - - if (!apiKey || !project) { + const data = use(dataPromis); + console.log(data); + if (!data) { return null; } + const [apiKey, project] = data; + return ( "prevent-close", + label: "Continue", + onClick: async () => setOpen(false), props: { type: "submit", form: formId, @@ -56,14 +61,23 @@ export function OnboardingDialog() { onClose={() => setOpen(false)} > {/* TODO: Add document link */} - + Here are your new API keys. Please copy this to your .env.local file. Detailed instruction can be founder here. + + + NEXT_PUBLIC_STACK_PROJECT_ID={project.id} + + + NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY={apiKey.publishableClientKey} + + + STACK_SECRET_SERVER_KEY={apiKey.secretServerKey} + + - NEXT_PUBLIC_STACK_PROJECT_ID={project.id} - NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY={apiKey.publishableClientKey} - STACK_SECRET_SERVER_KEY={apiKey.secretServerKey} + Note that the secret server key is only shown once. You need to generate a new one if you lose it. diff --git a/packages/stack-server/src/app/(main)/(protected)/projects/header.tsx b/packages/stack-server/src/app/(main)/(protected)/projects/header.tsx index 6f9c8e961..01768545e 100644 --- a/packages/stack-server/src/app/(main)/(protected)/projects/header.tsx +++ b/packages/stack-server/src/app/(main)/(protected)/projects/header.tsx @@ -1,11 +1,9 @@ -"use client"; - +"use client";; import { Logo } from "@/components/logo"; -import { Sheet, SheetProps, Select, Option, SelectOption, Stack, Typography } from "@mui/joy"; -import * as React from 'react'; +import { Sheet, SheetProps, Stack } from "@mui/joy"; export function Header(props: SheetProps & { headerHeight: number }) { - const { ...sheetProps } = props; + const { headerHeight, ...sheetProps } = props; return ( - + diff --git a/packages/stack-server/src/app/(main)/(protected)/projects/page-client.tsx b/packages/stack-server/src/app/(main)/(protected)/projects/page-client.tsx index fe4a98fd6..d748bb0d5 100644 --- a/packages/stack-server/src/app/(main)/(protected)/projects/page-client.tsx +++ b/packages/stack-server/src/app/(main)/(protected)/projects/page-client.tsx @@ -124,6 +124,7 @@ function CreateProjectDialog(props: { open: boolean, onClose(): void, onInvalida displayName: `${formData.get('name')}`, description: `${formData.get('description')}`, }); + props.onInvalidate(); props.onClose(); } finally {