1
//native
2
type Discourse = {
3
apiKey: string;
4
defaultHost: string;
5
apiUsername: string;
6
};
7
/**
8
* Change password
9
*
10
*/
11
export async function main(
12
auth: Discourse,
13
token: string,
14
body: { username: string; password: string },
15
) {
16
const url = new URL(
17
`https://${auth.defaultHost}/users/password-reset/${token}.json`,
18
);
19
20
const response = await fetch(url, {
21
method: "PUT",
22
headers: {
23
"Content-Type": "application/json",
24
"API-KEY": auth.apiKey,
25
"API-USERNAME": auth.apiUsername,
26
},
27
body: JSON.stringify(body),
28
});
29
if (!response.ok) {
30
const text = await response.text();
31
throw new Error(`${response.status} ${text}`);
32
}
33
return await response.text();
34
35