diff --git a/api/queries/functions/api.ts b/api/queries/functions/api.ts index 225d911d..52628053 100644 --- a/api/queries/functions/api.ts +++ b/api/queries/functions/api.ts @@ -1,6 +1,7 @@ import { Api } from "@jellyfin/sdk"; import { fetchCredentials } from "./storage"; import { client } from "../../client"; +import _ from "lodash"; /** * A promise to build an authenticated Jellyfin API client @@ -9,7 +10,12 @@ import { client } from "../../client"; export const createApi: () => Promise = async () => { return fetchCredentials() .then(credentials => { - return client.createApi(credentials.server, credentials.password); + + if (!_.isUndefined(credentials)) + throw new Error("No credentials exist for the current user") + + return client.createApi(credentials!.server, credentials!.password); + }).catch((rejection) => { return Promise.reject(rejection) }) diff --git a/api/queries/functions/storage.ts b/api/queries/functions/storage.ts index a93eaec3..7e4badcd 100644 --- a/api/queries/functions/storage.ts +++ b/api/queries/functions/storage.ts @@ -5,7 +5,7 @@ import * as Keychain from "react-native-keychain" import { JellifyServer } from "../../../types/JellifyServer"; -export const fetchCredentials : () => Promise = () => new Promise(async (resolve, reject) => { +export const fetchCredentials : () => Promise = () => new Promise(async (resolve, reject) => { console.log("Attempting to use stored credentials"); @@ -14,15 +14,15 @@ export const fetchCredentials : () => Promise = ( console.debug(`REMOVE THIS::Server name ${server.name}`); if (_.isEmpty(server.url)) { - console.warn("Server url was empty"); - return reject(new Error("Unable to retrieve credentials without a server URL")); + console.warn("Unable to retrieve credentials without a server URL"); + resolve(undefined); } const keychain = await Keychain.getInternetCredentials(server.url!); if (!keychain) { console.warn("No keychain for server address - signin required"); - return reject(new Error("Unable to retrieve credentials for server address from keychain")); + resolve(undefined); } console.log("Successfully retrieved keychain");