mirror of
https://github.com/Jellify-Music/App.git
synced 2026-04-22 09:58:46 -05:00
getting the hook to return properl;y
This commit is contained in:
@@ -3,14 +3,14 @@ import { AsyncStorageKeys } from "../../../enums/async-storage-keys"
|
||||
import _ from "lodash";
|
||||
|
||||
|
||||
export const fetchServerUrl : () => Promise<string> | never = async () => {
|
||||
export const fetchServerUrl : () => Promise<string | null> = async () => {
|
||||
|
||||
console.log("Attempting to fetch server address from storage");
|
||||
|
||||
let url = await AsyncStorage.getItem(AsyncStorageKeys.ServerUrl)!;
|
||||
|
||||
if (_.isNull(url))
|
||||
throw Error("Server URL was null")
|
||||
Promise.reject("Stored server address was null");
|
||||
|
||||
return url;
|
||||
}
|
||||
@@ -2,17 +2,19 @@ import { useQuery } from "@tanstack/react-query"
|
||||
import { QueryKeys } from "../../enums/query-keys"
|
||||
import { fetchCredentials } from "./functions/keychain"
|
||||
import { fetchServerUrl } from "./functions/storage";
|
||||
import _ from "lodash";
|
||||
|
||||
export const useCredentials = useQuery({
|
||||
queryKey: [QueryKeys.Credentials],
|
||||
queryFn: async () => {
|
||||
|
||||
try {
|
||||
let serverUrl = await fetchServerUrl();
|
||||
return await fetchCredentials(serverUrl);
|
||||
} catch(error: any) {
|
||||
console.error("Exception occurred using credentials", error);
|
||||
Promise.reject(`Unable to use server credentials: ${error}`);
|
||||
let serverUrl = await fetchServerUrl();
|
||||
|
||||
if (_.isNull(serverUrl)) {
|
||||
Promise.reject("Can't fetch credentials if server address doesn't exist yet :|");
|
||||
return;
|
||||
}
|
||||
|
||||
return await fetchCredentials(serverUrl);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user