Skip to content

Commit

Permalink
refactor: implement basic auth compatible with vercel (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
aahna-ashina committed May 28, 2022
1 parent 39002bd commit d6f7597
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions server/pages/_middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { NextFetchEvent, NextRequest } from 'next/server'

export function middleware(req: NextRequest, ev: NextFetchEvent) {
console.log('middleware')

console.log('req.page.name:', req.page.name)

const basicAuth = req.headers.get('authorization')
console.log('basicAuth:', basicAuth)

if (!basicAuth) {
return new Response(
'401 Unauthorized', {
status: 401,
headers: {
'WWW-Authenticate': 'Basic realm="Secure Area"',
},
})
}
}

0 comments on commit d6f7597

Please sign in to comment.