Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

πŸ’„ Explain missing admin access instead of returning a 404 (#2877)

Luke Vellae28ea12f7646
diff --git a/apps/docs/self-hosting/control-panel.mdx b/apps/docs/self-hosting/control-panel.mdx
index 27bae8826..ee50ee207 100644
--- a/apps/docs/self-hosting/control-panel.mdx
+++ b/apps/docs/self-hosting/control-panel.mdx
@@ -27,3 +27,12 @@ To claim admin rights:
4. Click this button to elevate your account to an administrator.
Once claimed, this user can manage other users and settings.
+
+## Troubleshooting
+
+If you see an **Administrator access required** message when visiting `/control-panel`, the account you are signed in with does not have the admin role. This usually means:
+
+- The `INITIAL_ADMIN_EMAIL` environment variable is not set, or
+- It does not match the email address of the account you are signed in with.
+
+Update `INITIAL_ADMIN_EMAIL` to match your account's email address, restart your instance, and visit `/control-panel` again to claim admin rights. Alternatively, an existing administrator can grant your account the admin role from the **Users** section of the Control Panel.
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 686ccc0f4..68607db2f 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -34,6 +34,9 @@
"addTimeOption": "Add time option",
"addToCalendar": "Add to Calendar",
"admin": "Admin",
+ "adminAccessRequired": "Administrator access required",
+ "adminAccessRequiredDescription": "You need administrator access to view this page.",
+ "adminAccessRequiredSelfHostedHint": "If you are the owner of this instance, check that INITIAL_ADMIN_EMAIL is set to the email address of the administrator account.",
"adminRoleDescription": "Full member access plus space management and member permissions",
"adminRoleRequired": "You need to be an admin to perform this action",
"adminSetup": "Admin Setup",
@@ -75,6 +78,7 @@
"authErrorsUserBanned": "This account has been banned. Please contact support if you believe this is an error.",
"authErrorsUserNotFound": "No account found with this email address. Please check the email or register for a new account.",
"back": "Back",
+ "backToHome": "Back to home",
"banned": "Banned",
"banUser": "Ban user",
"banUserDesc": "Are you sure you want to ban <b>{email}</b>? They will be signed out and won't be able to log in.",
@@ -691,6 +695,7 @@
"share": "Share",
"showPassword": "Show password",
"shrink": "Shrink",
+ "signedInAs": "You're signed in as:",
"signIn": "Sign in",
"signOut": "Sign Out",
"signUp": "Sign Up",
diff --git a/apps/web/src/app/[locale]/admin-setup/page.tsx b/apps/web/src/app/[locale]/admin-setup/page.tsx
index 452c00fb1..68e937819 100644
--- a/apps/web/src/app/[locale]/admin-setup/page.tsx
+++ b/apps/web/src/app/[locale]/admin-setup/page.tsx
@@ -1,8 +1,8 @@
import { buttonVariants } from "@rallly/ui";
-import { CrownIcon } from "lucide-react";
+import { CrownIcon, LockIcon } from "lucide-react";
import type { Metadata } from "next";
import Link from "next/link";
-import { notFound, redirect } from "next/navigation";
+import { redirect } from "next/navigation";
import {
EmptyState,
EmptyStateDescription,
@@ -10,6 +10,7 @@ import {
EmptyStateIcon,
EmptyStateTitle,
} from "@/components/empty-state";
+import { IfCloudHosted, IfSelfHosted } from "@/components/environment";
import { isInitialAdmin } from "@/features/instance-settings/utils";
import { getCurrentUser } from "@/features/user/loaders";
import { Trans } from "@/i18n/client";
@@ -17,6 +18,7 @@ import { getTranslation } from "@/i18n/server";
import { getPathname } from "@/lib/pathname";
import { buildSafeRedirectUrl } from "@/lib/utils/redirect";
import { MakeMeAdminButton } from "./make-me-admin-button";
+import { SignedInAs } from "./signed-in-as";
export default async function AdminSetupPage() {
// Read the role from the database β€” the session cookie cache can hold
@@ -37,7 +39,57 @@ export default async function AdminSetupPage() {
}
if (!isInitialAdmin(user.email)) {
- notFound();
+ return (
+ <main id="main-content" tabIndex={-1} className="flex h-dvh flex-col p-4">
+ <EmptyState className="flex-1">
+ <EmptyStateIcon>
+ <LockIcon />
+ </EmptyStateIcon>
+ <EmptyStateTitle>
+ <Trans
+ i18nKey="adminAccessRequired"
+ defaults="Administrator access required"
+ />
+ </EmptyStateTitle>
+ <EmptyStateDescription>
+ <IfCloudHosted>
+ <Trans
+ i18nKey="adminAccessRequiredDescription"
+ defaults="You need administrator access to view this page."
+ />
+ </IfCloudHosted>
+ <IfSelfHosted>
+ <Trans
+ i18nKey="adminAccessRequiredSelfHostedHint"
+ defaults="If you are the owner of this instance, check that INITIAL_ADMIN_EMAIL is set to the email address of the administrator account."
+ />
+ </IfSelfHosted>
+ </EmptyStateDescription>
+ <EmptyStateFooter className="flex gap-2">
+ <Link href="/" className={buttonVariants()}>
+ <Trans i18nKey="backToHome" defaults="Back to home" />
+ </Link>
+ <IfSelfHosted>
+ <a
+ target="_blank"
+ rel="noreferrer"
+ href="https://support.rallly.co/self-hosting/control-panel"
+ className={buttonVariants({ variant: "primary" })}
+ >
+ <Trans i18nKey="learnMore" defaults="Learn more" />
+ </a>
+ </IfSelfHosted>
+ </EmptyStateFooter>
+ </EmptyState>
+ <div className="pb-6">
+ <SignedInAs
+ name={user.name}
+ email={user.email}
+ image={user.image ?? undefined}
+ />
+ </div>
+ </main>
+ );
}
return (
diff --git a/apps/web/src/app/[locale]/admin-setup/signed-in-as.tsx b/apps/web/src/app/[locale]/admin-setup/signed-in-as.tsx
new file mode 100644
index 000000000..8513be65c
--- /dev/null
+++ b/apps/web/src/app/[locale]/admin-setup/signed-in-as.tsx
@@ -0,0 +1,49 @@
+"use client";
+
+import { Button } from "@rallly/ui/button";
+import React from "react";
+import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
+import { Trans } from "@/i18n/client";
+import { signOut } from "@/lib/auth-client";
+
+export function SignedInAs({
+ name,
+ email,
+ image,
+}: {
+ name: string;
+ email: string;
+ image?: string;
+}) {
+ const [isSigningOut, setIsSigningOut] = React.useState(false);
+
+ return (
+ <div className="flex flex-wrap items-center justify-center gap-x-3 gap-y-2 text-sm">
+ <span className="text-muted-foreground">
+ <Trans i18nKey="signedInAs" defaults="You're signed in as:" />
+ </span>
+ <span className="flex items-center gap-2">
+ <OptimizedAvatarImage src={image} name={name} size="sm" />
+ <span className="font-medium">{email}</span>
+ </span>
+ <Button
+ variant="ghost"
+ size="sm"
+ loading={isSigningOut}
+ onClick={() => {
+ setIsSigningOut(true);
+ signOut()
+ .catch(() => {
+ // Reload even if sign out fails: the server re-renders from
+ // the real cookie state.
+ })
+ .finally(() => {
+ window.location.reload();
+ });
+ }}
+ >
+ <Trans i18nKey="signOut" defaults="Sign out" />
+ </Button>
+ </div>
+ );
+}
diff --git a/apps/web/src/features/user/loaders.ts b/apps/web/src/features/user/loaders.ts
index 1f8b00818..81423023b 100644
--- a/apps/web/src/features/user/loaders.ts
+++ b/apps/web/src/features/user/loaders.ts
@@ -1,8 +1,7 @@
import "server-only";
-import { notFound, redirect } from "next/navigation";
+import { redirect } from "next/navigation";
import { cache } from "react";
-import { isInitialAdmin } from "@/features/instance-settings/utils";
import { getUser, getUserHasNoAccounts } from "@/features/user/data";
import type { UserDTO } from "@/features/user/schema";
import { getSession, getSessionState } from "@/lib/auth";
@@ -67,9 +66,9 @@ export const requireUser = cache(async (): Promise<UserDTO> => {
/**
* Gate for server pages that require an admin user. Authorized against
* the database β€” the session cookie cache can hold a stale role.
- * Redirects to /login when unauthenticated, to /admin-setup when the
- * user is the initial admin but not yet promoted, and returns 404 for
- * everyone else.
+ * Redirects to /login when unauthenticated and to /admin-setup for
+ * everyone else β€” that page either offers the initial admin promotion
+ * or explains that administrator access is missing.
*/
export const requireAdmin = cache(async () => {
const user = await getCurrentUser();
@@ -82,11 +81,7 @@ export const requireAdmin = cache(async () => {
}
if (user.role !== "admin") {
- if (isInitialAdmin(user.email)) {
- redirect("/admin-setup");
- }
-
- notFound();
+ redirect("/admin-setup");
}
return user;
diff --git a/apps/web/tests/admin-setup.spec.ts b/apps/web/tests/admin-setup.spec.ts
index 96eadb61f..d829a1661 100644
--- a/apps/web/tests/admin-setup.spec.ts
+++ b/apps/web/tests/admin-setup.spec.ts
@@ -51,7 +51,7 @@ test.describe("Admin Setup Page Access", () => {
).toBeVisible();
});
- test("should show 'not found' for a regular user (not initial admin, not admin role)", async ({
+ test("should explain missing admin access to a regular user (not initial admin, not admin role)", async ({
page,
}) => {
await createUserInDb({
@@ -62,7 +62,8 @@ test.describe("Admin Setup Page Access", () => {
await loginWithEmail(page, { email: REGULAR_USER_EMAIL });
await page.goto("/admin-setup");
- await expect(page.getByText("Page not found")).toBeVisible();
+ await expect(page.getByText("Administrator access required")).toBeVisible();
+ await expect(page.getByText(REGULAR_USER_EMAIL)).toBeVisible();
});
test("should redirect an existing admin user to control-panel", async ({
@@ -79,7 +80,7 @@ test.describe("Admin Setup Page Access", () => {
await expect(page).toHaveURL("/control-panel");
});
- test("should show 'not found' if INITIAL_ADMIN_EMAIL in env is different from user's email", async ({
+ test("should explain missing admin access if INITIAL_ADMIN_EMAIL in env is different from user's email", async ({
page,
}) => {
await createUserInDb({
@@ -90,7 +91,7 @@ test.describe("Admin Setup Page Access", () => {
await loginWithEmail(page, { email: OTHER_USER_EMAIL });
await page.goto("/admin-setup");
- await expect(page.getByText("Page not found")).toBeVisible();
+ await expect(page.getByText("Administrator access required")).toBeVisible();
});
test("initial admin can make themselves admin using the button", async ({
diff --git a/apps/web/tests/control-panel.spec.ts b/apps/web/tests/control-panel.spec.ts
index d21edd15b..50d71fad4 100644
--- a/apps/web/tests/control-panel.spec.ts
+++ b/apps/web/tests/control-panel.spec.ts
@@ -27,7 +27,9 @@ test.describe
await expect(page).toHaveURL("/login?redirectTo=%2Fcontrol-panel");
});
- test("should show not found for a non-admin user", async ({ page }) => {
+ test("should explain missing admin access to a non-admin user", async ({
+ page,
+ }) => {
await createUserInDb({
email: CONTROL_PANEL_NON_ADMIN_EMAIL,
name: "Control Panel Non-Admin",
@@ -37,7 +39,10 @@ test.describe
await page.goto("/control-panel");
- await expect(page.getByText("Page not found")).toBeVisible();
+ await expect(page).toHaveURL(/.*\/admin-setup/);
+ await expect(
+ page.getByText("Administrator access required"),
+ ).toBeVisible();
});
test("should allow an admin user to access the control panel", async ({