diff --git a/apps/dashboard/src/app/(main)/(protected)/(outside-dashboard)/projects/actions.ts b/apps/dashboard/src/app/(main)/(protected)/(outside-dashboard)/projects/actions.ts
index 7e5ef6acf..02df30736 100644
--- a/apps/dashboard/src/app/(main)/(protected)/(outside-dashboard)/projects/actions.ts
+++ b/apps/dashboard/src/app/(main)/(protected)/(outside-dashboard)/projects/actions.ts
@@ -1,16 +1,16 @@
"use server";
import { isRemoteDevelopmentEnvironmentEnabled } from "@/lib/remote-development-environment/env";
-async function getStackServerApp() {
+async function getServerApp() {
if (isRemoteDevelopmentEnvironmentEnabled()) {
throw new Error("Team invitation management is not available in the remote development environment dashboard.");
}
- return (await import("@/stack/server")).stackServerApp;
+ return (await import("@/stack/server")).getStackServerApp();
}
export async function revokeInvitation(teamId: string, invitationId: string) {
"use server";
- const stackServerApp = await getStackServerApp();
+ const stackServerApp = await getServerApp();
const user = await stackServerApp.getUser();
const team = await user?.getTeam(teamId);
if (!team) {
@@ -24,7 +24,7 @@ export async function revokeInvitation(teamId: string, invitationId: string) {
}
export async function listInvitations(teamId: string) {
- const stackServerApp = await getStackServerApp();
+ const stackServerApp = await getServerApp();
const user = await stackServerApp.getUser();
const team = await user?.getTeam(teamId);
if (!team) {
@@ -39,7 +39,7 @@ export async function listInvitations(teamId: string) {
}
export async function inviteUser(teamId: string, email: string, origin: string) {
- const stackServerApp = await getStackServerApp();
+ const stackServerApp = await getServerApp();
const callbackUrl = new URL(stackServerApp.urls.teamInvitation, origin).toString();
const user = await stackServerApp.getUser();
const team = await user?.getTeam(teamId);
diff --git a/apps/dashboard/src/app/(main)/integrations/featurebase/sso/page.tsx b/apps/dashboard/src/app/(main)/integrations/featurebase/sso/page.tsx
index 84463e98c..a47197137 100644
--- a/apps/dashboard/src/app/(main)/integrations/featurebase/sso/page.tsx
+++ b/apps/dashboard/src/app/(main)/integrations/featurebase/sso/page.tsx
@@ -1,4 +1,4 @@
-import { stackServerApp } from "@/stack/server";
+import { getStackServerApp } from "@/stack/server";
import { getEnvVariable } from "@stackframe/stack-shared/dist/utils/env";
import { getOrCreateFeaturebaseUser } from "@stackframe/stack-shared/dist/utils/featurebase";
import { urlString } from "@stackframe/stack-shared/dist/utils/urls";
@@ -21,7 +21,7 @@ export default async function FeaturebaseSSO({
return
Missing return_to parameter. Please go back and try again.
;
}
- const user = await stackServerApp.getUser();
+ const user = await getStackServerApp().getUser();
if (!user) {
redirect(urlString`/handler/sign-in?after_auth_return_to=${urlString`/integrations/featurebase/sso?return_to=${returnTo}`}`);
}
diff --git a/apps/dashboard/src/app/(main)/integrations/oauth-confirm-page.tsx b/apps/dashboard/src/app/(main)/integrations/oauth-confirm-page.tsx
index dc53deee6..3c635138e 100644
--- a/apps/dashboard/src/app/(main)/integrations/oauth-confirm-page.tsx
+++ b/apps/dashboard/src/app/(main)/integrations/oauth-confirm-page.tsx
@@ -1,4 +1,4 @@
-import { stackServerApp } from "@/stack/server";
+import { getStackServerApp } from "@/stack/server";
import { getEnvVariable } from "@stackframe/stack-shared/dist/utils/env";
import { StackAssertionError } from "@stackframe/stack-shared/dist/utils/errors";
import { redirect } from "next/navigation";
@@ -18,7 +18,7 @@ export default async function IntegrationConfirmPage(props: {
const onContinue = async (options: { projectId: string, projectName?: string }) => {
"use server";
- const user = await stackServerApp.getUser();
+ const user = await getStackServerApp().getUser();
if (!user) {
return { error: "unauthorized" };
}
diff --git a/apps/dashboard/src/app/layout.tsx b/apps/dashboard/src/app/layout.tsx
index 81a4e53c7..0fae3c442 100644
--- a/apps/dashboard/src/app/layout.tsx
+++ b/apps/dashboard/src/app/layout.tsx
@@ -13,8 +13,10 @@ import '../polyfills';
import './globals.css';
import { LayoutClient } from './layout-client';
+const apiUrl = getPublicEnvVar('NEXT_PUBLIC_STACK_API_URL');
+
export const metadata: Metadata = {
- metadataBase: new URL(getPublicEnvVar('NEXT_PUBLIC_STACK_API_URL') || ''),
+ ...apiUrl ? { metadataBase: new URL(apiUrl) } : {},
title: {
default: 'Stack Auth Dashboard',
template: '%s | Stack Auth',
@@ -23,12 +25,12 @@ export const metadata: Metadata = {
openGraph: {
title: 'Stack Auth Dashboard',
description: 'Stack Auth is the open-source Auth0 alternative, and the fastest way to add authentication to your web app.',
- images: [`${getPublicEnvVar('NEXT_PUBLIC_STACK_API_URL')}/open-graph-image.png`]
+ ...apiUrl ? { images: [`${apiUrl}/open-graph-image.png`] } : {},
},
twitter: {
title: 'Stack Auth Dashboard',
description: 'Stack Auth is the open-source Auth0 alternative, and the fastest way to add authentication to your web app.',
- images: [`${getPublicEnvVar('NEXT_PUBLIC_STACK_API_URL')}/open-graph-image.png`]
+ ...apiUrl ? { images: [`${apiUrl}/open-graph-image.png`] } : {},
},
};
diff --git a/apps/dashboard/src/stack/server.tsx b/apps/dashboard/src/stack/server.tsx
index 0e67eeaf6..2185c2ac0 100644
--- a/apps/dashboard/src/stack/server.tsx
+++ b/apps/dashboard/src/stack/server.tsx
@@ -5,10 +5,17 @@ import { StackServerApp } from "@stackframe/stack";
import { StackAssertionError } from "@stackframe/stack-shared/dist/utils/errors";
import { stackClientApp } from "./client";
-if (isRemoteDevelopmentEnvironmentEnabled()) {
- throw new StackAssertionError("stackServerApp is not available in the local remote development environment dashboard.");
-}
+type InternalServerApp = StackServerApp;
+let _stackServerApp: InternalServerApp | undefined;
-export const stackServerApp = new StackServerApp({
- inheritsFrom: stackClientApp,
-});
+export function getStackServerApp(): InternalServerApp {
+ if (!_stackServerApp) {
+ if (isRemoteDevelopmentEnvironmentEnabled()) {
+ throw new StackAssertionError("stackServerApp is not available in the local remote development environment dashboard.");
+ }
+ _stackServerApp = new StackServerApp({
+ inheritsFrom: stackClientApp,
+ });
+ }
+ return _stackServerApp;
+}
diff --git a/packages/stack-cli/src/commands/whoami.ts b/packages/stack-cli/src/commands/whoami.ts
index df4daee94..ec19e238b 100644
--- a/packages/stack-cli/src/commands/whoami.ts
+++ b/packages/stack-cli/src/commands/whoami.ts
@@ -8,7 +8,7 @@ export function registerWhoamiCommand(program: Command) {
.description("Show the currently logged-in Stack Auth CLI user")
.action(async () => {
const flags = program.opts();
- const auth = resolveSessionAuth(flags);
+ const auth = resolveSessionAuth();
const user = await getInternalUser(auth);
const teams = await user.listTeams();