Skip to content

Commit

Permalink
added dashboard routes protection
Browse files Browse the repository at this point in the history
  • Loading branch information
WTanardi committed May 26, 2023
1 parent 4a15a42 commit 55a02f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/app/dashboard/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ import RecipeAdd from "./RecipeAdd";
import OrderAdd from "./OrderAdd";
import IngredientAdd from "./IngredientAdd";
import { LogoutButton } from "@/components/Buttons";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";

const AdminDashboard = () => {
const AdminDashboard = async () => {
const [activeTab, setActiveTab] = useState<string>("tab1");

const handleTabChange = (tabName: string) => {
setActiveTab(tabName);
};

const session = await getServerSession();

if (!session) {
redirect("/login");
}

return (
<>
<div className="flex mx-auto border-black border-t-2">
Expand Down
5 changes: 2 additions & 3 deletions src/app/dashboard/user/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import "@fortawesome/fontawesome-svg-core/styles.css";
import "../../../../fontawesome";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import { redirect } from "next/navigation";
import { PrismaClient } from "@prisma/client";
import { LogoutButton } from "@/components/Buttons";
Expand Down Expand Up @@ -55,10 +54,10 @@ const getRecipes = async () => {
};

const UserDashboard = async () => {
const session = await getServerSession(authOptions);
const session = await getServerSession();

if (!session) {
redirect("/api/auth/signin");
redirect("/login");
}

const [ingredients, categories, recipes] = await Promise.all([
Expand Down

0 comments on commit 55a02f0

Please sign in to comment.