Skip to content

Instantly share code, notes, and snippets.

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

Sanna Jammeh sannajammeh

🏠
Working from home
View GitHub Profile
@sannajammeh
sannajammeh / _middleware.ts
Last active January 6, 2022 17:24
NextJS edge middleware with Firebase Auth
/**
* Use this edge middleware anywhere in your pages directory to prevent unauthorized access.
* in this case we prevent access to certain pages without the author role present on the token.
* Make sure the token is present on req.cookies by setting it on the client side or posting to a server side endpoint
* and setting refresh token via firebase admin SDK. See https://firebase.google.com/docs/auth/admin/manage-cookies
* Be sure to rotate tokens frequently on client or server.
*/
// eslint-disable-next-line @next/next/no-server-import-in-page
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";