Auth & User Management
Cookie-based authentication and user lifecycle management. Auth routes use session cookies (withCredentials: true). No manual token storage required. With a publishable key, methods that read or change an account act on the signed-in user only; methods marked "secret key only" must run on your server.
SDK Setup
1import { NeuctraAuthix } from "@neuctra/authix";
2
3const authix = new NeuctraAuthix({
4 appName: "MyApp",
5 baseUrl: "https://server.authix.neuctra.com/api",
6 // Publishable key in browser code; a secret key (sk_live_…) only on a server
7 apiKey: "pk_live_xxxxxxxx_xxxxxxxxxxxxxxxx",
8 appId: "your_app_id_here",
9});signupUser
POST /users/signup
| Param | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Display name |
| string | Yes | Email address | |
| password | string | Yes | Password |
| username | string | No | Unique username |
| phone | string | null | No | Phone number |
| address | string | null | No | Address |
| avatarUrl | string | null | No | Avatar URL |
| isActive | boolean | No | Active status |
| role | string | No | User role |
1await authix.signupUser({
2 name: "John Doe",
3 email: "[email protected]",
4 password: "securePassword123",
5});Works with a publishable or secret key and sets the HTTP-only session cookie (withCredentials: true). Public signup always creates role 'user'.
loginUser
POST /users/login
| Param | Type | Required | Description |
|---|---|---|---|
| string | Yes | Email address | |
| password | string | Yes | Password |
1await authix.loginUser({
2 email: "[email protected]",
3 password: "securePassword123",
4});Sets HTTP-only session cookie.
logoutUser
POST /users/logout
Returns: { success: boolean }
1await authix.logoutUser();Clears session cookie and reloads page in browser environments.
checkUserSession
GET /users/session
Returns: CheckSessionResponse
1const session = await authix.checkUserSession();Returns { authenticated: false } on server (SSR safe).
getUser
GET /users/:appId/user?id=... or ?username=...
| Param | Type | Required | Description |
|---|---|---|---|
| id | string | No | User ID |
| username | string | No | Username |
1await authix.getUser({ id: "user_id" });Requires a secret key — server only. Looks up any user in the app by id or username; a publishable key gets 403 INSUFFICIENT_SCOPE.
getUserProfile
POST /users/profile
| Param | Type | Required | Description |
|---|---|---|---|
| userId | string | Yes | User ID |
1await authix.getUserProfile({ userId: "id" });With a publishable key the user comes from the session cookie and userId is ignored (401 NO_USER_SESSION if nobody is signed in). A secret key reads any user by id.
updateUser
PUT /users/update/:userId
| Param | Type | Required | Description |
|---|---|---|---|
| userId | string | Yes | User ID to update |
| appId | string | Yes | Required to verify app ownership |
| name | string | No | Display name |
| username | string | null | No | Unique username |
| string | No | ||
| password | string | No | Password |
| phone | string | null | No | Phone |
| address | string | null | No | Address |
| avatarUrl | string | null | No | Avatar URL |
| isActive | boolean | No | Active status |
| role | string | No | Role |
| settings | unknown | No | Arbitrary app-defined settings |
| packageInfo | unknown | No | Arbitrary app-defined package info |
| notifications | unknown | No | Arbitrary app-defined notifications |
| extraInfo | unknown | No | Arbitrary app-defined extra info |
1await authix.updateUser({
2 userId: "id",
3 appId: "your_app_id_here",
4 name: "Updated Name",
5});With a publishable key this updates the signed-in user only (userId is ignored): password, isActive and packageInfo are refused — use changePassword for passwords — role is ignored, and changing email needs currentPassword. A secret key may update any user and set every field.
changePassword
PUT /users/change-password/:userId
| Param | Type | Required | Description |
|---|---|---|---|
| userId | string | Yes | User ID |
| currentPassword | string | Yes | Current password |
| newPassword | string | Yes | New password |
1await authix.changePassword({
2 userId: "id",
3 currentPassword: "old",
4 newPassword: "new",
5});Requires the current password. With a publishable key it changes the signed-in user's password; a secret key may name any user. Changing a password ends the user's existing sessions.
requestEmailVerificationOTP
POST /users/send-verify-otp/:userId
| Param | Type | Required | Description |
|---|---|---|---|
| userId | string | Yes | User ID |
| string | Yes |
1await authix.requestEmailVerificationOTP({
2 userId: "id",
3 email: "[email protected]",
4});OTP verification flow. Five wrong guesses discard the code; request a new one.
verifyEmail
POST /users/verify-email
| Param | Type | Required | Description |
|---|---|---|---|
| string | Yes | ||
| otp | string | Yes | OTP |
1await authix.verifyEmail({
2 email: "[email protected]",
3 otp: "123456",
4});Email verification endpoint.
requestResetUserPasswordOTP
POST /users/forgot-password
| Param | Type | Required | Description |
|---|---|---|---|
| string | Yes |
1await authix.requestResetUserPasswordOTP({
2 email: "[email protected]",
3});No session required; works with a publishable key. Always returns 200 with 'If an account exists…', whether or not the email is registered.
resetUserPassword
POST /users/reset-password
| Param | Type | Required | Description |
|---|---|---|---|
| string | Yes | ||
| otp | string | Yes | OTP |
| newPassword | string | Yes | New password |
1await authix.resetUserPassword({
2 email: "[email protected]",
3 otp: "123456",
4 newPassword: "newPassword",
5});Public password reset flow. Five wrong guesses discard the code. Resetting a password ends the user's existing sessions.
checkIfUserExists
GET /users/check-user/:userId
| Param | Type | Required | Description |
|---|---|---|---|
| userId | string | Yes | User ID |
Returns: CheckUserResponse
1await authix.checkIfUserExists("user_id");Requires a secret key — server only. A publishable key gets 403 INSUFFICIENT_SCOPE.
deleteUser
DELETE /users/delete/:userId
| Param | Type | Required | Description |
|---|---|---|---|
| userId | string | Yes | User ID |
1await authix.deleteUser({ userId: "id" });With a publishable key this deletes the signed-in user only (userId is ignored). A secret key may delete any user.
Security Model
Neuctra Authix uses secure HTTP-only cookies for authentication. Sessions are handled via withCredentials: true. The SDK auto-injects appId into requests.