Register()

register(dto: any, signal?: AbortSignal)

Registers a new user by creating an account with the provided credentials. Required fields should be configured in config.json.

await client.auth().register({ username: "mike", password: "mikes-wife-birthday", email: "mike@example.com" })

Important

The password will be hashed if you configure it as described in the REST documentation.

Result

The register() method returns a token object containing both an access token and a refresh token. If the request is made from a browser environment, only the access token is included in the response, while the refresh token is stored in an HTTP-only cookie.

const token = await client.auth().register({ username: "mike", password: "mikes-wife-birthday", email: "mike@example.com" })
//console.log(token)

// result:
// {
//      access: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
// }

Suggestion

If you need to save the token for future use, retrieve it from the client.auth().on("register", token => { /* save token */ }) event instead of this result.

Edit this page on Github
© 2025 kav3.com. Crafted with and dedication.