Skip to content

Commit

Permalink
Merge branch 'admin-view-job-page' of https://github.com/Web-Team-IIT…
Browse files Browse the repository at this point in the history
…I-Gymkhana/tpc-frontend into admin-view-job-page
  • Loading branch information
Princekumarofficial committed Jul 11, 2024
2 parents cfee20b + 1a38ba0 commit 4d356c7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";



const adminRoutes = ["/admin/company", "/admin/students", "/admin/job"];
const studentRoutes = [
"/student/jobs",
Expand All @@ -11,11 +13,28 @@ const studentRoutes = [
"/student/resumes",
];
const recruiterRoutes = ["/recruiter/jaf", "/recruiter/prevjaf"];
const facultyRoutes = ["/faculty", "/faculty/profile"];

export function middleware(request: NextRequest) {
const userCookie = request.cookies.get("user");
const user = userCookie ? JSON.parse(userCookie.value) : null;

if (request.nextUrl.pathname === "/" && !user) {
return NextResponse.redirect(new URL("/login", request.url));
}
if (request.nextUrl.pathname === "/" && user?.role === "STUDENT") {
return NextResponse.redirect(new URL("/student/profile", request.url));
}
if (request.nextUrl.pathname === "/" && user?.role === "ADMIN") {
return NextResponse.redirect(new URL("admin/profile", request.url));
}
if (request.nextUrl.pathname === "/" && user?.role === "RECRUITER") {
return NextResponse.redirect(new URL("/recruiter/profile", request.url));
}
if (request.nextUrl.pathname === "/" && user?.role === "FACULTY") {
return NextResponse.redirect(new URL("/faculty", request.url));
}

if (
user?.role !== "ADMIN" &&
adminRoutes.includes(request.nextUrl.pathname)
Expand All @@ -35,6 +54,15 @@ export function middleware(request: NextRequest) {
) {
return NextResponse.redirect(new URL("/login", request.url));
}
if (
user?.role !== "FACULTY" &&
facultyRoutes.includes(request.nextUrl.pathname) &&
request.url.includes("/faculty")
) {
return NextResponse.redirect(new URL("/login", request.url));
}



return NextResponse.next();
}

0 comments on commit 4d356c7

Please sign in to comment.