Skip to content

Commit

Permalink
feat(web): maintenance mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mrevanzak committed May 20, 2024
1 parent 5fe5d27 commit 09af369
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@tanstack/react-query": "^5.36.0",
"@tanya.in/ui": "*",
"@vercel/analytics": "^1.2.2",
"@vercel/edge-config": "^1.1.0",
"geist": "^1.3.0",
"next": "^14.2.0",
"next-auth": "beta",
Expand Down
8 changes: 8 additions & 0 deletions apps/web/src/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Footer } from "@/components/footer";
import { Navbar } from "@/components/navbar";
import { SidebarWrapper } from "@/components/sidebar/sidebar";
import { auth } from "@/lib/auth";
import { get } from "@vercel/edge-config";

export default async function AuthLayout(props: {
user: React.ReactNode;
Expand All @@ -10,6 +11,13 @@ export default async function AuthLayout(props: {
const session = await auth();
const isAdmin = session?.user.role === "admin";

const isMaintenance = await get("maintenance");

if (isMaintenance && !isAdmin)
throw new Error(
"Unfortunately, the site is under maintenance. We'll be back soon!",
);

return (
<div className="flex flex-row">
{session?.user.role === "admin" && <SidebarWrapper />}
Expand Down
15 changes: 13 additions & 2 deletions apps/web/src/app/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,34 @@ export default function Error({
error: Error & { digest?: string };
reset: () => void;
}) {
const isUnauthorized = error.message?.includes("Unauthorized");
const isUnauthorized = error.message.includes("Unauthorized");
const isMaintenance = error.message.includes("maintenance");

return (
<div className="flex min-h-screen flex-col items-center justify-center space-y-4 text-center ">
<RiAlarmWarningFill
size={60}
className="drop-shadow-glow animate-flicker text-danger"
/>
<h1>{error.message ?? "Oops, something went wrong!"}</h1>
<h1 className="max-w-prose text-balance">{error.message}</h1>
<Button
className="!mt-12"
onClick={async () => {
if (isUnauthorized) return await signOut();
reset();
}}
>
{isUnauthorized ? "Go to sign in page" : "Try again"}
</Button>
{isMaintenance && (
<Button
onClick={async () => {
await signOut();
}}
>
Sign in as admin
</Button>
)}
</div>
);
}
1 change: 1 addition & 0 deletions apps/web/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const env = createEnv({
*/
server: {
AUTH_SECRET: z.string().min(1),
EDGE_CONFIG: z.string().optional(),
},

/**
Expand Down
Binary file modified bun.lockb
Binary file not shown.
23 changes: 21 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
# bun ./bun.lockb --hash: 048E957A172A1470-f544c46eb9a05411-59635A21C479BCCD-abc18af4cfd4e811
# bun ./bun.lockb --hash: 4AB29C4D64AFDB5A-c6f10467f5468719-66966C22DFFEBA53-3cf06cdf4bbd5045


"@ai-sdk/[email protected]":
Expand Down Expand Up @@ -2375,6 +2375,7 @@
"@tanstack/react-query" "^5.36.0"
"@tanya.in/ui" "packages/ui"
"@vercel/analytics" "^1.2.2"
"@vercel/edge-config" "^1.1.0"
geist "^1.3.0"
next "^14.2.0"
next-auth "beta"
Expand Down Expand Up @@ -2655,6 +2656,19 @@
dependencies:
server-only "^0.0.1"

"@vercel/edge-config@^1.1.0":
version "1.1.0"
resolved "https://registry.npmjs.org/@vercel/edge-config/-/edge-config-1.1.0.tgz"
integrity sha512-es/4BzzKfyUilL5E1knR42MZHJqHMRfqitrnv18gVZZUha9ywrX3qNoCrPsNMJ1HS8xAAz/FJEyel7YFIDfKoQ==
dependencies:
ts-essentials "9.4.1"
"@vercel/edge-config-fs" "0.1.0"

"@vercel/[email protected]":
version "0.1.0"
resolved "https://registry.npmjs.org/@vercel/edge-config-fs/-/edge-config-fs-0.1.0.tgz"
integrity sha512-NRIBwfcS0bUoUbRWlNGetqjvLSwgYH/BqKqDN7vK1g32p7dN96k0712COgaz6VFizAm9b0g6IG6hR6+hc0KCPg==

"@vue/[email protected]":
version "3.4.27"
resolved "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.4.27.tgz"
Expand Down Expand Up @@ -7283,6 +7297,11 @@ ts-api-utils@^1.3.0:
resolved "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz"
integrity sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==

[email protected]:
version "9.4.1"
resolved "https://registry.npmjs.org/ts-essentials/-/ts-essentials-9.4.1.tgz"
integrity sha512-oke0rI2EN9pzHsesdmrOrnqv1eQODmJpd/noJjwj2ZPC3Z4N2wbjrOEqnsEgmvlO2+4fBb0a794DCna2elEVIQ==

ts-interface-checker@^0.1.9:
version "0.1.13"
resolved "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz"
Expand Down Expand Up @@ -7445,7 +7464,7 @@ typescript@^4.4.3:
resolved "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

typescript@*, typescript@>=2.7, typescript@>=3, typescript@>=4.2.0, typescript@>=4.9.5, typescript@>=5.0.0, typescript@^5.4.5:
typescript@*, typescript@>=2.7, typescript@>=3, typescript@>=4.1.0, typescript@>=4.2.0, typescript@>=4.9.5, typescript@>=5.0.0, typescript@^5.4.5:
version "5.4.5"
resolved "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz"
integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==
Expand Down

0 comments on commit 09af369

Please sign in to comment.