MCPcopy Create free account
hub / github.com/vercel/examples / middleware

Function middleware

edge-middleware/basic-auth-password/middleware.ts:7–22  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

5}
6
7export default function middleware(req: NextRequest) {
8 const basicAuth = req.headers.get('authorization')
9 const url = req.nextUrl
10
11 if (basicAuth) {
12 const authValue = basicAuth.split(' ')[1]
13 const [user, pwd] = atob(authValue).split(':')
14
15 if (user === '4dmin' && pwd === 'testpwd123') {
16 return NextResponse.next()
17 }
18 }
19 url.pathname = '/api/auth'
20
21 return NextResponse.rewrite(url)
22}

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected