mirror of
https://github.com/anultravioletaurora/Jellify.git
synced 2026-05-07 05:59:35 -05:00
ca558b558f
getting api client to get added to context when signed in Server name should stay on auth screen even when a different server address is requested
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { fetchServer } from "../../queries/functions/storage";
|
|
import { JellyfinCredentials } from "../../types/jellyfin-credentials";
|
|
import * as Keychain from "react-native-keychain"
|
|
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
|
import { JellifyServer } from "../../../types/JellifyServer";
|
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
import { AsyncStorageKeys } from "../../../enums/async-storage-keys";
|
|
import { buildApiClient } from "../../client";
|
|
|
|
interface ServerMutationParams {
|
|
serverUrl: string,
|
|
}
|
|
|
|
export const serverMutation = async (serverUrl: string) => {
|
|
|
|
console.log("Mutating server URL");
|
|
|
|
if (!!!serverUrl)
|
|
throw Error("Server URL is empty")
|
|
|
|
const api = buildApiClient(serverUrl);
|
|
|
|
console.log(`Created API client for ${api.basePath}`)
|
|
return await getSystemApi(api).getPublicSystemInfo();
|
|
}
|
|
|
|
export const mutateServer = async (server: JellifyServer | undefined) => {
|
|
return await AsyncStorage.setItem(AsyncStorageKeys.ServerUrl, JSON.stringify(server));
|
|
}
|
|
|
|
export const mutateServerCredentials = async (credentials: JellyfinCredentials) => {
|
|
return Keychain.setInternetCredentials((await fetchServer()).url, credentials.username, credentials.accessToken!);
|
|
} |