Files
formbricks-formbricks/apps/web/lib/apiKeys.ts
Matti Nannt 9cc836a775 Clean up + Bugfixes (#443)
* format code

* fix building issue in database package

* update turbo config and package jsons

* update error package with more information and license

* fix typescript issues in ui package

* update package-lock

* update packages

* clean dependencies in web

* clean up dependencies in demo & formbricks-com

* remove unsused template file

* remove legacy capture endpoint

* remove unfinished client endpoints

* clean up unused functions

* fix formbricks not loading on invalid session

* update readme
2023-06-28 13:07:51 +02:00

40 lines
1.1 KiB
TypeScript

import useSWR from "swr";
import { fetcher } from "@formbricks/lib/fetcher";
export const useApiKeys = (environmentId: string) => {
const { data, error, mutate } = useSWR(`/api/v1/environments/${environmentId}/api-keys`, fetcher);
return {
apiKeys: data,
isLoadingApiKeys: !error && !data,
isErrorApiKeys: error,
mutateApiKeys: mutate,
};
};
export const createApiKey = async (environmentId: string, apiKey = {}) => {
try {
const res = await fetch(`/api/v1/environments/${environmentId}/api-keys`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(apiKey),
});
return await res.json();
} catch (error) {
console.error(error);
throw Error(`createApiKey: unable to create api-key: ${error.message}`);
}
};
export const deleteApiKey = async (environmentId: string, apiKey) => {
try {
const res = await fetch(`/api/v1/environments/${environmentId}/api-keys/${apiKey.id}`, {
method: "DELETE",
});
return await res.json();
} catch (error) {
console.error(error);
throw Error(`deleteApiKey: unable to delete api-key: ${error.message}`);
}
};