added in basic auth from env variable

This commit is contained in:
2021-11-12 12:14:17 +00:00
parent c0e44c223e
commit d96c072bfe
6 changed files with 21 additions and 10 deletions
+11 -6
View File
@@ -9,6 +9,17 @@ class MyDocument extends Document {
let useGATracking = false;
// remove this block when not need after softlaunch
let hasBasicAuth =
typeof process.env.BASIC_AUTH_CREDENTIALS != "undefined";
if (ctx.req && ctx.res) {
hasBasicAuth &&
(await basicAuthMiddleware(ctx.req, ctx.res, {
users: process.env.BASIC_AUTH_CREDENTIALS,
}));
}
if (ctx.req && ctx.req.headers.cookie) {
typeof ctx.req.cookies.CookiePolicy != "undefined"
? JSON.parse(ctx.req.cookies.CookiePolicy).usage == "accepted"
@@ -19,12 +30,6 @@ class MyDocument extends Document {
useGATracking = false;
}
// if (ctx.req && ctx.res) {
// await basicAuthMiddleware(ctx.req, ctx.res, {
// users: process.env.BASIC_AUTH_CREDENTIALS,
// });
// }
return { ...initialProps, useGATracking };
}