Auth & user management
Every method for creating an end user, signing them in, verifying their email, resetting their password, and reading or deleting their account. All arguments are keyword-only.
The session lives on the client
login_user() stores a cookie on the client's requests.Session, and every later call on that client acts as that user. In a script that is exactly what you want. In a web server it is a serious bug: one shared client would hand the first visitor's session to the next.
In a web application, either construct a short-lived client per request, or use a shared secret-key client that never signs anyone in and pass user_id explicitly — taken from a session your server has verified, never from the request.
signup_user
POST /api/users/signup
authix.signup_user(
*, name: str, email: str, password: str,
username: str | None = None,
phone: str | None = None,
address: str | None = None,
) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | Display name. |
| str | Yes | Unique within this app. The same address can exist in another app. | |
| password | str | Yes | Sent over HTTPS and stored as a bcrypt hash. Never stored in plaintext. |
| username | str | No | Optional handle, usable with get_user(). |
| phone | str | No | Optional. |
| address | str | No | Optional. |
Returns: dict — the created user
1user = authix.signup_user(
2 name="Ada Lovelace",
3 email="[email protected]",
4 password="a-long-passphrase",
5)
6
7print(user["user"]["id"])Throws
login_user
POST /api/users/login
authix.login_user(*, email: str, password: str) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| str | Yes | The user's email. | |
| password | str | Yes | Their password. |
Returns: dict — the signed-in user
1result = authix.login_user(email="[email protected]", password="…")
2
3# The cookie is now on this client. Subsequent calls act as Ada.
4print(result["user"]["id"])Throws
logout_user
POST /api/users/logout
authix.logout_user() -> dictReturns: dict
1authix.logout_user()
2
3authix.check_user_session()
4# {"authenticated": False}check_user_session
GET /api/users/session
authix.check_user_session() -> dictReturns: dict — {"authenticated": bool, "user": dict | None}
1session = authix.check_user_session()
2
3if session["authenticated"]:
4 print(session["user"]["email"])
5else:
6 prompt_login()change_password
PUT /api/users/change-password/:id
authix.change_password(
*, user_id: str, current_password: str, new_password: str,
) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| user_id | str | Yes | Whose password to change. |
| current_password | str | Yes | Verified before the change is applied. |
| new_password | str | Yes | The replacement. |
Returns: dict
1authix.change_password(
2 user_id=user_id,
3 current_password=old,
4 new_password=new,
5)
6# Every session for this user is now invalid, including this one.Throws
request_email_verification_otp
POST /api/users/send-verify-otp/:id
authix.request_email_verification_otp(*, user_id: str, email: str) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| user_id | str | Yes | The user to verify. |
| str | Yes | Where to send the code. |
Returns: dict
1authix.request_email_verification_otp(user_id=user_id, email=email)verify_email
POST /api/users/verify-email
authix.verify_email(*, email: str, otp: str) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| str | Yes | The address being confirmed. | |
| otp | str | Yes | The code from the email. |
Returns: dict
1authix.verify_email(email=email, otp=code)Throws
request_reset_user_password_otp
POST /api/users/forgot-password
authix.request_reset_user_password_otp(*, email: str) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| str | Yes | Where to send the reset code. |
Returns: dict
1authix.request_reset_user_password_otp(email="[email protected]")reset_user_password
POST /api/users/reset-password
authix.reset_user_password(
*, email: str, otp: str, new_password: str,
) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| str | Yes | The account being reset. | |
| otp | str | Yes | The emailed code. |
| new_password | str | Yes | The new password. |
Returns: dict
1authix.reset_user_password(
2 email=email,
3 otp=code,
4 new_password=new_password,
5)Throws
get_user_profile
POST /api/users/profile
authix.get_user_profile(*, user_id: str) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| user_id | str | Yes | Whose profile to read. |
Returns: dict
1profile = authix.get_user_profile(user_id=user_id)get_user
GET /api/users/:appId/user
authix.get_user(
*, id: str | None = None, username: str | None = None,
) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| id | str | No | Look up by id. Pass this or username. |
| username | str | No | Look up by handle. |
Returns: dict
1user = authix.get_user(username="ada")Throws
update_user
PUT /api/users/update/:id
authix.update_user(*, user_id: str, **fields) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| user_id | str | Yes | Who to update. |
| **fields | Any | Yes | Profile fields to change: name, username, phone, address, avatar_url. |
Returns: dict
1authix.update_user(user_id=user_id, name="Ada L.", phone="+44…")delete_user
DELETE /api/users/delete/:userId
authix.delete_user(*, user_id: str) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| user_id | str | Yes | Who to delete. |
Returns: dict
1authix.delete_user(user_id=user_id)Throws
check_if_user_exists
GET /api/users/check-user/:id
authix.check_if_user_exists(user_id: str) -> dict| Param | Type | Required | Description |
|---|---|---|---|
| user_id | str | Yes | Positional, unlike the rest of the SDK. |
Returns: dict
1if authix.check_if_user_exists(user_id)["exists"]:
2 ...Throws
Do not build your own authorisation on these
A successful check_user_session() tells you who someone is. It does not tell you what they may do. Ownership is enforced by the API on every request, and your own rules — which screens, which records, which actions — belong in your code.
Related