Skip to content

Instantly share code, notes, and snippets.

@skolhustick
Created December 28, 2021 15:34
Show Gist options
  • Save skolhustick/2360b353db69d8824885a2506b79014c to your computer and use it in GitHub Desktop.
Save skolhustick/2360b353db69d8824885a2506b79014c to your computer and use it in GitHub Desktop.
import { getToken } from 'next-auth/jwt'
import { NextResponse } from 'next/server'
export async function middleware (req) {
const session = await getToken({
req,
secret: process.env.SECRET,
secureCookie: process.env.NEXTAUTH_URL?.startsWith('https://')
})
if (!session) return NextResponse.redirect('/api/auth/signin')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment