mirror of
https://github.com/Jellify-Music/App.git
synced 2026-01-10 04:50:33 -06:00
fix?
This commit is contained in:
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user