[website] Add basic auth (#422)
This commit is contained in:
parent
45e36b2360
commit
b63515e65f
|
@ -0,0 +1,25 @@
|
||||||
|
import { NextResponse } from 'next/server'
|
||||||
|
|
||||||
|
import type { NextRequest } from 'next/server'
|
||||||
|
|
||||||
|
export function middleware(req: NextRequest) {
|
||||||
|
const basicAuth = req.headers.get('authorization')
|
||||||
|
|
||||||
|
if (process.env.VERCEL_ENV !== 'production') {
|
||||||
|
return NextResponse.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (basicAuth) {
|
||||||
|
const auth = basicAuth.split(' ')[1]
|
||||||
|
const [user, password] = Buffer.from(auth, 'base64').toString().split(':')
|
||||||
|
|
||||||
|
if (user === 'status' && password === process.env.AUTH_PASSWORD) {
|
||||||
|
return NextResponse.next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NextResponse('Authentication Required', {
|
||||||
|
status: 401,
|
||||||
|
headers: { 'WWW-Authenticate': `Basic realm="website"` },
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue