Maximus upgradus
This commit is contained in:
+6
-8
@@ -1,5 +1,4 @@
|
||||
import * as DocumentPicker from "expo-document-picker";
|
||||
import { File } from "expo-file-system/next";
|
||||
import type { CodexAuth } from "@/types/codex";
|
||||
|
||||
export async function pickAndReadCodexAuth(): Promise<CodexAuth> {
|
||||
@@ -8,13 +7,11 @@ export async function pickAndReadCodexAuth(): Promise<CodexAuth> {
|
||||
copyToCacheDirectory: true,
|
||||
});
|
||||
|
||||
if (result.canceled) {
|
||||
throw new Error("PICKER_CANCELLED");
|
||||
}
|
||||
if (result.canceled) throw new Error("PICKER_CANCELLED");
|
||||
|
||||
const { uri } = result.assets[0];
|
||||
const file = new File(uri);
|
||||
const text = file.text();
|
||||
const response = await fetch(uri);
|
||||
const text = await response.text();
|
||||
|
||||
let parsed: Record<string, unknown>;
|
||||
try {
|
||||
@@ -23,8 +20,9 @@ export async function pickAndReadCodexAuth(): Promise<CodexAuth> {
|
||||
throw new Error("INVALID_JSON");
|
||||
}
|
||||
|
||||
const accessToken = parsed["accessToken"] as string | undefined;
|
||||
const accountId = parsed["accountId"] as string | undefined;
|
||||
const tokens = parsed["tokens"] as Record<string, unknown> | undefined;
|
||||
const accessToken = (tokens?.["access_token"] ?? parsed["accessToken"]) as string | undefined;
|
||||
const accountId = (tokens?.["account_id"] ?? parsed["accountId"]) as string | undefined;
|
||||
|
||||
if (!accessToken || typeof accessToken !== "string") {
|
||||
throw new Error("MISSING_ACCESS_TOKEN");
|
||||
|
||||
Reference in New Issue
Block a user