Skip to content

Commit

Permalink
Toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 16, 2023
1 parent b7d3e7c commit d206910
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
4 changes: 3 additions & 1 deletion apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@
"@trigger.dev/react": "^2.2.6",
"@trigger.dev/sdk": "^2.2.6",
"@trigger.dev/supabase": "^2.2.6",
"@vercel/edge-config": "^0.4.1",
"@vercel/toolbar": "^0.1.5",
"change-case": "^5.1.2",
"framer-motion": "^10.16.5",
"next": "14.0.3-canary.5",
"next-international": "^1.1.4",
"next-safe-action": "^5.0.3",
"next-themes": "^0.2.1",
"next-usequerystate": "^1.12.0",
"sharp": "^0.32.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.48.2",
"recharts": "^2.9.3",
"sharp": "^0.32.6",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
7 changes: 6 additions & 1 deletion apps/dashboard/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Deployments } from "@/components/deployments";
import { StaffToolbar } from "@/components/staff-toolbar";
import { ThemeProvider } from "@/components/theme-provider";
import "@/styles/globals.css";
import "@midday/ui/globals.css";
import { Toaster } from "@midday/ui/toaster";
import { cn } from "@midday/ui/utils";
import type { Metadata } from "next";
import { Instrument_Sans } from "next/font/google";
import type { ReactElement } from "react";
import { type ReactElement, Suspense } from "react";

const fontSans = Instrument_Sans({
subsets: ["latin"],
Expand Down Expand Up @@ -36,6 +37,10 @@ export default function Layout({ children }: { children: ReactElement }) {
<Toaster />
<Deployments />
</ThemeProvider>

<Suspense>
<StaffToolbar />
</Suspense>
</body>
</html>
);
Expand Down
16 changes: 16 additions & 0 deletions apps/dashboard/src/components/staff-toolbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createClient } from "@midday/supabase/server";
import { get } from "@vercel/edge-config";
import { VercelToolbar } from "@vercel/toolbar/next";

export async function StaffToolbar() {
const supabase = createClient();

const {
data: { session },
} = await supabase.auth.getSession();
const admins = await get("admins");

const isAdmin = admins?.includes(session.user.id);

return isAdmin ? <VercelToolbar /> : null;
}
13 changes: 2 additions & 11 deletions apps/dashboard/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createClient } from "@midday/supabase/middleware";
import { get } from "@vercel/edge-config";
import { createI18nMiddleware } from "next-international/middleware";
import { NextRequest, NextResponse } from "next/server";

Expand All @@ -8,16 +9,6 @@ const I18nMiddleware = createI18nMiddleware({
urlMappingStrategy: "rewrite",
});

const ADMINS = [
"ec10c095-8cf7-4ba3-a62e-98f2a3d40c4c",
"7d723617-c2e1-4b71-8bf4-fb02479b264a",
"efea0311-0786-4f70-9b5a-63e3efa5d319",
"2f76981b-fc66-479c-8203-521a5a1f734a",
"3cb7ad12-907e-49c6-9f3a-ea3eeb1d34cf",
"71908de2-2727-43a8-8a3f-4ae203faa4c5",
"a9f6e6f2-8d58-4cf7-a3e7-312be3ee9560", // Ali Saheli
];

export async function middleware(request: NextRequest) {
const response = I18nMiddleware(request);
const { supabase } = createClient(request, response);
Expand All @@ -30,7 +21,7 @@ export async function middleware(request: NextRequest) {

if (
data.session &&
!ADMINS.includes(data.session.user.id) &&
!(await get("beta"))?.includes(data.session.user.id) &&
request.nextUrl.pathname !== "/closed"
) {
return NextResponse.redirect(new URL("/closed", request.url));
Expand Down
Binary file modified bun.lockb
Binary file not shown.

0 comments on commit d206910

Please sign in to comment.