tl-api
Version:
TPLink Router API
18 lines (15 loc) • 415 B
JavaScript
export const fetchTokenId = async (
baseUrl,
{ authTimes = 1, sessionId } = {}
) => {
const res = await fetch(new URL("/", baseUrl).href, {
method: "GET",
headers: {
Referer: new URL("/", baseUrl).href,
Cookie: `loginErrorShow=${authTimes}; JSESSIONID=${sessionId}`,
},
});
const html = await res.text();
const [, token] = html.match(/var token="([^"]*)"/);
return token;
};