here is my code
Code: Select all
const getToken = (username: string, password: string) =>
fetch("https://api.opensubtitles.com/api/v1/login", {
method: "POST",
headers: new Headers({
Accept: "application/json",
"Api-Key": apiKey,
"Content-Type": "application/json",
"User-Agent": userAgent,
}),
body: JSON.stringify({ username, password }),
}).then((response) =>
response.ok
? response.json().then(({ token }) => token as string)
: response.text().then((data) => {
throw new Error(JSON.stringify(data));
}),
);