This commit is contained in:
Violet Caulfield
2024-10-20 10:23:13 -05:00
parent ee685fd9ca
commit 79bdb83a5c
2 changed files with 11 additions and 5 deletions

View File

@@ -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<Api> = 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)
})

View File

@@ -5,7 +5,7 @@ import * as Keychain from "react-native-keychain"
import { JellifyServer } from "../../../types/JellifyServer";
export const fetchCredentials : () => Promise<Keychain.SharedWebCredentials> = () => new Promise(async (resolve, reject) => {
export const fetchCredentials : () => Promise<Keychain.SharedWebCredentials | undefined> = () => new Promise(async (resolve, reject) => {
console.log("Attempting to use stored credentials");
@@ -14,15 +14,15 @@ export const fetchCredentials : () => Promise<Keychain.SharedWebCredentials> = (
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");