mirror of
https://github.com/Jellify-Music/App.git
synced 2026-05-01 16:09:44 -05:00
moving hooks out of backend since that isn't correct
This commit is contained in:
@@ -3,10 +3,13 @@ import { usePublicApi } from "../queries";
|
||||
import { useServerUrl } from "../queries/storage";
|
||||
import { JellyfinCredentials } from "../types/jellyfin-credentials";
|
||||
import { MutationKeys } from "../../enums/mutation-keys";
|
||||
import { createPublicApi } from "../query-functions/api";
|
||||
import { fetchServerUrl } from "../query-functions/storage";
|
||||
|
||||
export const authenticateWithCredentials = useMutation({
|
||||
mutationKey: [MutationKeys.AuthenticationWithCredentials],
|
||||
mutationFn: (credentials: JellyfinCredentials) => {
|
||||
return usePublicApi(useServerUrl.data!).data!.authenticateUserByName(credentials.username, credentials.password!);
|
||||
mutationFn: async (credentials: JellyfinCredentials) => {
|
||||
createPublicApi(await fetchServerUrl())
|
||||
.authenticateUserByName(credentials.username, credentials.password!);
|
||||
},
|
||||
})
|
||||
+2
-1
@@ -4,6 +4,7 @@ import { getDeviceNameSync, getUniqueIdSync } from "react-native-device-info"
|
||||
import { QueryKeys } from "../enums/query-keys";
|
||||
import { useCredentials } from "./queries/keychain";
|
||||
import { name, version } from "../package.json"
|
||||
import { createPublicApi } from "./query-functions/api";
|
||||
|
||||
export const client : Jellyfin = new Jellyfin({
|
||||
clientInfo: {
|
||||
@@ -19,7 +20,7 @@ export const client : Jellyfin = new Jellyfin({
|
||||
export const usePublicApi = (serverUrl: string) => useQuery({
|
||||
queryKey: [QueryKeys.PublicApi, serverUrl],
|
||||
queryFn: ({ queryKey }) => {
|
||||
return client.createApi(serverUrl);
|
||||
createPublicApi(queryKey[1])
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
+7
-15
@@ -1,21 +1,13 @@
|
||||
import { UseQueryResult, useQuery } from "@tanstack/react-query"
|
||||
import * as Keychain from "react-native-keychain"
|
||||
import { ArtistModel } from "../../models/ArtistModel"
|
||||
import { Api } from "@jellyfin/sdk"
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||
import { AsyncStorageKeys } from "../../enums/async-storage-keys"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
import { QueryKeys } from "../../enums/query-keys"
|
||||
import { useServerUrl } from "./storage"
|
||||
import { fetchCredentials } from "../query-functions/keychain"
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { AsyncStorageKeys } from "../../enums/async-storage-keys";
|
||||
import { fetchServerUrl } from "../query-functions/storage";
|
||||
|
||||
export const useCredentials = useQuery({
|
||||
queryKey: [QueryKeys.Credentials],
|
||||
queryFn: () => {
|
||||
return Keychain.getInternetCredentials(useServerUrl.data!)
|
||||
.then((keychain) => {
|
||||
if (!keychain)
|
||||
throw new Error("Jellyfin server credentials not stored in keychain");
|
||||
|
||||
return keychain as Keychain.SharedWebCredentials
|
||||
});
|
||||
queryFn: async () => {
|
||||
return fetchCredentials(await fetchServerUrl())
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Api } from "@jellyfin/sdk";
|
||||
import { client } from "../queries";
|
||||
|
||||
|
||||
|
||||
export const createPublicApi: (serverUrl: string) => Api = (serverUrl) => {
|
||||
return client.createApi(serverUrl);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import * as Keychain from "react-native-keychain"
|
||||
|
||||
export const fetchCredentials = (serverUrl: string) => {
|
||||
return Keychain.getInternetCredentials(serverUrl)
|
||||
.then((keychain) => {
|
||||
if (!keychain)
|
||||
throw new Error("Jellyfin server credentials not stored in keychain");
|
||||
|
||||
return keychain as Keychain.SharedWebCredentials
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage"
|
||||
import { AsyncStorageKeys } from "../../enums/async-storage-keys"
|
||||
import _ from "lodash";
|
||||
|
||||
|
||||
export const fetchServerUrl : () => Promise<string> = async () => {
|
||||
|
||||
let url = await AsyncStorage.getItem(AsyncStorageKeys.ServerUrl)!;
|
||||
|
||||
if (_.isNull(url))
|
||||
throw Error("Server URL was null")
|
||||
|
||||
return url;
|
||||
}
|
||||
Reference in New Issue
Block a user