Files
pubky-core/pubky/pkg/test/utils.js
SHAcollision 6386f1ae43 feat: signup tokens (#80)
* Add admin and signup config

* Add signup tokens API, db, admin endpoint

* Add client api for signup codes

* Add tests and fixes

* Fix wasm build

* Lint

* enable and use same admin pswd on all test homeservers

* fix pr review comments

* Add nodejs and browser signup token to tests

* update signup example

* admin authing as layer

* Update pubky-homeserver/src/core/routes/auth.rs

Co-authored-by: Severin Alexander Bühler <8782386+SeverinAlexB@users.noreply.github.com>

* Update pubky-homeserver/src/core/routes/auth.rs

Co-authored-by: Severin Alexander Bühler <8782386+SeverinAlexB@users.noreply.github.com>

* rename getSignupToken util

* add is_used() SignupToken method

---------

Co-authored-by: Severin Alexander Bühler <8782386+SeverinAlexB@users.noreply.github.com>
2025-03-17 15:58:58 -04:00

25 lines
883 B
JavaScript

/**
* Util to request a signup token from the given homeserver as admin.
*
* @param {Client} client - An instance of your client.
* @param {string} homeserver_address - The homeserver's public key (as a domain-like string).
* @param {string} [adminPassword="admin"] - The admin password (defaults to "admin").
* @returns {Promise<string>} - The signup token.
* @throws Will throw an error if the request fails.
*/
export async function createSignupToken(client, homeserver_address ="localhost:6286", adminPassword = "admin") {
const adminUrl = `http://${homeserver_address}/admin/generate_signup_token`;
const response = await client.fetch(adminUrl, {
method: "GET",
headers: {
"X-Admin-Password": adminPassword,
},
});
if (!response.ok) {
throw new Error(`Failed to get signup token: ${response.statusText}`);
}
return response.text();
}