Replace NodeJS dict aliases with maps and named field reads
This commit is contained in:
+9
-8
@@ -12,7 +12,7 @@ import {
|
||||
} from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
import { isNotFound, isObject } from "#common";
|
||||
import { field, isNotFound, isObject } from "#common";
|
||||
|
||||
interface CodexApiKey {
|
||||
kind: "api-key";
|
||||
@@ -89,15 +89,16 @@ async function readCodexAuth(path: string): Promise<string> {
|
||||
} catch {
|
||||
throw new Error("invalid Codex login");
|
||||
}
|
||||
const tokens = isObject(value) ? value["tokens"] : undefined;
|
||||
const authMode = field(value, "auth_mode");
|
||||
const tokens = field(value, "tokens");
|
||||
if (
|
||||
!isObject(value) ||
|
||||
typeof value["auth_mode"] !== "string" ||
|
||||
value["auth_mode"] === "" ||
|
||||
typeof authMode !== "string" ||
|
||||
authMode === "" ||
|
||||
!isObject(tokens) ||
|
||||
!["access_token", "refresh_token", "id_token", "account_id"].every(
|
||||
(name) => typeof tokens[name] === "string" && tokens[name] !== "",
|
||||
)
|
||||
!["access_token", "refresh_token", "id_token", "account_id"].every((name) => {
|
||||
const token = field(tokens, name);
|
||||
return typeof token === "string" && token !== "";
|
||||
})
|
||||
) {
|
||||
throw new Error("invalid Codex login");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user