Skip to content

Commit

Permalink
feat: added admin check on prompt pages
Browse files Browse the repository at this point in the history
  • Loading branch information
edinstance committed Oct 19, 2024
1 parent 20a53d8 commit 8545ffd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/prompts/[promptId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function editPromtPage({
});
console.log(prompt);
const updatePrompt = useMutation(api.prompts.updatePrompt);
const isAdmin = useQuery(api.users.isAdmin);

const [promptName, setPromptName] = useState("");
const [promptText, setPromptText] = useState("");
Expand Down Expand Up @@ -48,6 +49,10 @@ export default function editPromtPage({
router.push("/prompts");
};

if (!isAdmin) {
redirect("/");
}

return (
<div className="container mx-auto min-h-screen pb-24 py-12 gap-8">
<form className="py-6 px-6 h-full" onSubmit={handleSubmit}>
Expand Down
8 changes: 7 additions & 1 deletion app/prompts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import {
import { api } from "@/convex/_generated/api";
import { useMutation, useQuery } from "convex/react";
import Link from "next/link";
import { useRouter,redirect } from "next/navigation";
import { useRouter, redirect } from "next/navigation";

const Page = () => {
const prompts = useQuery(api.prompts.getAllPrompts);
const enablePrompt = useMutation(api.prompts.enablePrompt);
const deletePrompt = useMutation(api.prompts.deletePrompt);
const createPrompt = useMutation(api.prompts.createPrompt);

const isAdmin = useQuery(api.users.isAdmin);

const router = useRouter();

const handleCreatePrompt = async () => {
Expand All @@ -30,6 +32,10 @@ const Page = () => {
router.push(`/prompts/${newPromptId}`);
};

if (!isAdmin) {
redirect("/");
}

return (
<div className="container mx-auto min-h-screen py-12 pb-24 gap-8">
<div className="flex justify-between mb-4">
Expand Down

0 comments on commit 8545ffd

Please sign in to comment.