mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-11 14:10:15 -07:00
27 lines
743 B
TypeScript
27 lines
743 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
export const config = {
|
|
matcher: ['/', '/index', '/labs', '/launch', '/news', '/personas' ],
|
|
}
|
|
|
|
export function middleware(req: NextRequest) {
|
|
const basicAuth = req.headers.get('authorization')
|
|
const url = req.nextUrl
|
|
|
|
const envUsername = process.env.BASIC_AUTH_USERNAME
|
|
const envPassword = process.env.BASIC_AUTH_PASSWORD
|
|
|
|
if (basicAuth) {
|
|
const authValue = basicAuth.split(' ')[1]
|
|
const [user, pwd] = atob(authValue).split(':')
|
|
|
|
if (user === envUsername && pwd === envPassword) {
|
|
return NextResponse.next()
|
|
}
|
|
}
|
|
|
|
// If the user is not authenticated, redirect to the auth page
|
|
url.pathname = '/api/auth/auth'
|
|
|
|
return NextResponse.rewrite(url)
|
|
} |