Skip to content

Commit 830a610

Browse files
committed
fix(auth): correctly parse AUTH_SKIP environment variable
1 parent 3560d38 commit 830a610

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/app.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ function getOption(
3838
return env;
3939
}
4040

41+
/**
42+
* Parse a boolean-like environment variable.
43+
* Returns `true` for 1/true/yes/y, `false` for 0/false/no/n, and
44+
* `undefined` if the variable is not set or unrecognized.
45+
*/
46+
function getBooleanOption(
47+
envName: string,
48+
required: boolean = true,
49+
): boolean | undefined {
50+
const val = getOption(envName, required);
51+
if (val === undefined) return undefined;
52+
const v = val.trim().toLowerCase();
53+
if (["1", "true", "yes", "y"].includes(v)) return true;
54+
if (["0", "false", "no", "n"].includes(v)) return false;
55+
return undefined;
56+
}
57+
4158
// Pass --options via CLI arguments in command to enable these options.
4259
const options: AppOptions = {
4360
// Launching lots of services on the server,
@@ -49,14 +66,7 @@ const options: AppOptions = {
4966
// mongoUri: getOption("MONGO_URI")!,
5067
authDiscoveryURL: getOption("AUTH_DISCOVERY_URL")!,
5168
authClientID: getOption("AUTH_CLIENT_ID")!,
52-
authSkip: (() => {
53-
const opt = getOption("AUTH_SKIP", false);
54-
if (opt !== undefined) {
55-
return Boolean(opt);
56-
} else {
57-
return undefined;
58-
}
59-
})(),
69+
authSkip: getBooleanOption("AUTH_SKIP", false),
6070
};
6171

6272
// Support Typebox

0 commit comments

Comments
 (0)