Core concept
Publishable and secret keys
Neuctra Authix issues two kinds of API key. A publishable key goes in browser and mobile code and reaches only the signed-in user's own account. A secret key stays on your server and has full account authority.
Two keys, two places
Both are sent as the x-api-key header, and every SDK takes either one in its apiKey field. The server decides what a key may do from its own records, not from anything the caller claims.
| Publishable key | Secret key | |
|---|---|---|
| Prefix | pk_live_… | sk_live_… (older ak_live_… keys are secret keys) |
| Where to use | Browser and mobile code | Your server only, in an environment variable |
| Sign-in flows | Yes | Yes |
| Own profile and data | Signed-in user only — taken from the session cookie | Any user, by id |
| Read app data | Yes | Yes |
| Write app data | No | Yes |
| List, search or read other users | No | Yes |
| Set role, isActive, packageInfo | No | Yes |
| From a browser | Needs the app's allowed origins set | Refused — 403 SECRET_KEY_IN_BROWSER |
New accounts get one of each. Keys are created, copied and revoked only in the dashboard — the API Keys page has a Type selector — and no API key can create, list or revoke keys.
What a publishable key can do
Everything an end user does for themselves, and nothing more.
- Sign up, log in, log out, check the session, send and verify the email OTP, and request and complete a password reset.
- Read and change the signed-in user's own profile —
/users/profile, update, change password and delete — and their own user data. The user comes from the session cookie; anyuserIdin the URL or body is ignored. - Read app data, including search.
A publishable key cannot:
- List, search or read other users —
getUsers,getUser,checkUserand every/app/global/*route. - Add, update or delete app data.
- Set
role,isActiveorpackageInfo. - Change a password through
updateUser— usechangePasswordwith the current password. - Change the email address without passing
currentPassword.
A copied publishable key is not enough
Anyone can read a publishable key from your bundle. That is safe because everything private it reaches also needs the signed-in user's session cookie. Without a live session, own-data routes answer 401 NO_USER_SESSION. A session ends on logout, password change or reset, and deactivation.
Allowed origins and mobile apps
Set on the app's Access tab in the dashboard.
From a browser, a publishable key works only once the app's allowed origins are set; until then requests are refused with 403 ORIGINS_NOT_CONFIGURED. The session cookie travels cross-site, so without an origin list any website could act as your signed-in users. Add your production origins, and http://localhost:<port> while developing.
Native mobile apps send no Origin header, so they cannot pass an origin check. Leave allowed origins empty for the app a mobile client uses — a publishable key still limits it to the signed-in user.
What a key looks like
Only the tail is secret. The prefix is a lookup handle and is safe to put in a log line.
pk_live_a1b2c3d4_9f8e7d6c5b4a39281706f5e4d3c2b1a09f8e7d6c5b4a3928
│ │ │ └── 48 hex characters — the secret part
│ │ └── lookup handle, safe to log
│ └── environment: live or test
└── kind: pk = publishable, sk = secret (older ak keys are secret)At rest the server stores a SHA-256 hash of the key plus an encrypted copy, so you can copy a key again from the dashboard after creating it.
Using the keys
1// Browser or mobile code — publishable key
2const authix = new NeuctraAuthix({
3 appId: APP_ID,
4 apiKey: "pk_live_xxxxxxxx_xxxxxxxxxxxxxxxx",
5});
6
7// Server only — secret key from the environment
8const authixAdmin = new NeuctraAuthix({
9 appId: APP_ID,
10 apiKey: process.env.AUTHIX_SECRET_KEY,
11});Only trusted server code should receive a secret key. Authix refuses a secret key sent with an Origin header — that is, from a browser — with 403 SECRET_KEY_IN_BROWSER. A mobile build cannot be detected, so a secret key in one is simply leaked.
A secret key can act on any user by id, so your server must take the user id from a session it has verified — never from a URL, query string or form field.
Limiting a key to one app
Either kind of key can be limited to one app when you create it.
A key limited to one app is rejected with 403 KEY_APP_MISMATCH for every other app on the account. Use it to keep a leaked key from reaching apps it was never meant for.
Why the secret key must stay private
A leaked secret key can read and change every user and record on your account.
Treat it as an account credential
Do not put a secret key in a browser bundle, mobile binary, source control, or a client-exposed environment variable such as NEXT_PUBLIC_ or VITE_. Client code uses a publishable key; admin work — listing users, writing app data, setting roles — runs in your own backend.
If a secret key was ever shipped in frontend code, treat it as leaked: revoke it and move that code to a publishable key.
When the key is wrong for the endpoint
Key-related errors and what each one means.
{
"success": false,
"message": "You do not have permission to perform this action.",
"code": "INSUFFICIENT_SCOPE",
"hint": "Publishable keys only reach sign-in flows and the signed-in user's own data. Call this from your server with a secret key."
}| Code | Status | Meaning |
|---|---|---|
| INSUFFICIENT_SCOPE | 403 | A publishable key called a secret-only route. Move the call to your server. |
| NO_USER_SESSION | 401 | A publishable key called an own-data route with no live session. Sign the user in again. |
| SECRET_KEY_IN_BROWSER | 403 | A secret key arrived from a browser. Use a publishable key there. |
| ORIGINS_NOT_CONFIGURED | 403 | A publishable key was used from a browser before the app's allowed origins were set. |
| KEY_APP_MISMATCH | 403 | The key is limited to a different app. |
Each SDK raises INSUFFICIENT_SCOPE as InsufficientScopeError and NO_USER_SESSION as NoUserSessionError, so you can handle them separately from a wrong password.
Rotating a key
- Create the replacement, of the same type, in the dashboard first.
- Deploy it everywhere the old key is used. Both keys work during this window, so there is no outage.
- Revoke the old key. A revoked key is rejected with 401 on the next request — there is no cache to wait out.
Rotate a secret key immediately if
- It was committed to a repository, even a private one.
- It appeared in a client bundle — including via a
NEXT_PUBLIC_,VITE_or--dart-definevariable. - It was pasted into a log, a ticket, or a chat message.
Related