Skip to content

Commit

Permalink
Fix configuring basic auth docs (#3716)
Browse files Browse the repository at this point in the history
* Fix configuring basic auth docs

* Update www/docs/constructs/NextjsSite.about.md

Apply fix from @Roman86

Co-authored-by: Roman Kozodoi <romych.sync@gmail.com>

---------

Co-authored-by: Eduardo Pacheco <kanema665@gmail.com>
Co-authored-by: Roman Kozodoi <romych.sync@gmail.com>
  • Loading branch information
3 people committed Mar 26, 2024
1 parent a163c30 commit 63bf354
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions www/docs/constructs/NextjsSite.about.md
Expand Up @@ -494,15 +494,16 @@ new NextjsSite(stack, "Site", {
transform: (plan) => {
const username = "admin";
const password = "P@ssw0rd!";
const basicAuth = Buffer.from(`${username}:${password}`).toString("base64");
plan.cloudFrontFunctions.serverCfFunction.injections.push(`
var authHeaders = request.headers.authorization;
if (!authHeaders || authHeaders.value !== "Basic ${Buffer.from(${username}:${password}).toString('base64')
}"}) {
statusCode: 401,
statusDescription: "Unauthorized",
headers: {
"www-authenticate": { value: 'Basic realm="Secure Area"' }
}
if (request?.headers?.authorization?.value !== 'Basic ${basicAuth}') {
return {
statusCode: 401,
statusDescription: "Unauthorized",
headers: {
"www-authenticate": { value: 'Basic realm="Secure Area"' },
},
};
}
`);
},
Expand Down Expand Up @@ -575,7 +576,7 @@ new NextjsSite(stack, "Site", {
"OriginAccessIdentity",
"XXXXXXXX"
),
},
},
},
});
```
Expand Down

0 comments on commit 63bf354

Please sign in to comment.