Skip to content

Instantly share code, notes, and snippets.

View chapeee's full-sized avatar
🏠
Working from home

Rajneesh Aka Raj chapeee

🏠
Working from home
View GitHub Profile
@chapeee
chapeee / middleware.ts
Last active March 19, 2024 06:20
Protect Your Routes With Next 14 Routes Middleware
# If you are using Next 14 Make sure to plece this in Src folder.
# To learn more about middelware https://nextjs.org/docs/app/building-your-application/routing/middleware
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export async function middleware(request: NextRequest) {
const isLoggedin = () => {
// Mark isLoggedin as async
const authToken = request.cookies.get("authtokenlogIn");
if (authToken?.value == "1") {