Skip to content

Instantly share code, notes, and snippets.

View peuweb's full-sized avatar
🧪
Cooking some codes

Pedro Araujo peuweb

🧪
Cooking some codes
View GitHub Profile
@balazsorban44
balazsorban44 / _middleware.js
Last active July 5, 2023 09:36
NextAuth.js Auth Middleware for Next.js 12
import { getToken } from "next-auth/jwt"
import { NextResponse } from "next/server"
export async function middleware(req) {
// return early if url isn't supposed to be protected
if (!req.url.includes("/protected-url")) {
return NextResponse.next()
}
const session = await getToken({ req, secret: process.env.SECRET })