mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-01 03:11:44 -06:00
* 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
40 lines
1.1 KiB
TypeScript
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}`);
|
|
}
|
|
};
|