neuctra_authix_dart_package
Official Dart / Flutter SDK for the Neuctra Authix API.
A direct port of the TypeScript SDK shipped in @neuctra/authix (src/sdk/index.ts + src/sdk/interfaces.ts): same class name, same method names, same routes, same HTTP verbs, same per-method credential policy — expressed with Dart types.
Install
dependencies:
neuctra_authix_dart_package: ^1.0.0
Quick start
import 'package:neuctra_authix_dart_package/neuctra_authix_dart_package.dart';
final authix = NeuctraAuthix(
const NeuctraAuthixConfig(
appName: 'MyApp',
baseUrl: 'https://server.authix.neuctra.com/api',
apiKey: 'YOUR_API_KEY',
appId: 'YOUR_APP_ID',
),
);
try {
await authix.loginUser(
const LoginParams(email: 'ada@example.com', password: 'secret'),
);
final session = await authix.checkUserSession();
print(session.authenticated);
} on NeuctraAuthixException catch (e) {
print('${e.status}: ${e.message}');
} finally {
authix.close();
}
Configuration
| Field | Type | Notes |
|---|---|---|
appName |
String |
Required. Display name of the consuming app. |
baseUrl |
String |
Required. Trailing slash is stripped. |
apiKey |
String? |
Sent as x-api-key on every request. |
appId |
String? |
Injected into every request body and app-scoped route paths. |
Constructor options: client (bring your own http.Client), session (bring your own SessionStore), timeout (defaults to 30s).
API surface
All 30 methods from the TypeScript SDK, in the same order.
Users
| Dart | Verb | Route | Cookie |
|---|---|---|---|
signupUser(SignupParams) |
POST | /users/signup |
✅ |
loginUser(LoginParams) |
POST | /users/login |
✅ |
logoutUser({onLoggedOut}) |
POST | /users/logout |
✅ |
changePassword(ChangePasswordParams) |
PUT | /users/change-password/:userId |
✅ |
requestEmailVerificationOTP({userId, email}) |
POST | /users/send-verify-otp/:userId |
✅ |
verifyEmail({email, otp}) |
POST | /users/verify-email |
✅ |
checkUserSession() |
GET | /users/session |
✅ |
getUser({id, username}) |
GET | /users/:appId/user |
✅ |
updateUser(UpdateUserParams) |
PUT | /users/update/:userId |
✅ |
deleteUser(DeleteUserParams) |
DELETE | /users/delete/:userId |
✅ |
getUserProfile({userId}) |
POST | /users/profile |
✅ |
User security
| Dart | Verb | Route | Cookie |
|---|---|---|---|
requestResetUserPasswordOTP({email}) |
POST | /users/forgot-password |
❌ |
resetUserPassword({email, otp, newPassword}) |
POST | /users/reset-password |
❌ |
checkIfUserExists(String userId) |
GET | /users/check-user/:id |
❌ |
User data
| Dart | Verb | Route | Cookie |
|---|---|---|---|
addUserData(AddUserDataParams) |
POST | /users/:userId/data |
❌ |
getUserData<T>(GetUserAllDataParams) |
GET | /users/:userId/data |
❌ |
getSingleUserData(GetSingleUserDataParams) |
GET | /users/:userId/data/:dataId |
❌ |
searchInUserData({userId, category, q, keys}) |
POST | /users/:userId/data/search |
❌ |
updateUserData(UpdateUserDataParams) |
PUT | /users/:userId/data/:dataId |
❌ |
deleteUserData(DeleteUserDataParams) |
DELETE | /users/:userId/data/:dataId |
❌ |
App data
| Dart | Verb | Route | Cookie |
|---|---|---|---|
addAppData(AddAppDataParams) |
POST | /app/:appId/data/:dataCategory |
❌ |
getAppData([String? category]) |
GET | /app/:appId/app-data[/:category] |
❌ |
getSingleAppData({dataId}) |
GET | /app/:appId/data/:dataId |
❌ |
searchInAppData({category, q, keys}) |
POST | /app/:appId/app-data/search |
❌ |
updateAppData(UpdateAppDataParams) |
PATCH | /app/:appId/data/:dataId |
❌ |
deleteAppData(DeleteAppDataParams) |
DELETE | /app/:appId/data/:dataId |
❌ |
Global app search
| Dart | Verb | Route | Cookie |
|---|---|---|---|
getAllUsersFromApp<T>({cursor, limit}) |
POST | /app/global/:appId/all-app-users |
❌ |
searchInAllAppUsers({q, keys}) |
POST | /app/global/:appId/all-app-users/search |
❌ |
getAllUsersDataFromApp<T>({category, cursor, limit}) |
POST | /app/global/:appId/all-app-users-data |
❌ |
searchInAllAppUsersData({category, q, keys}) |
POST | /app/global/:appId/all-app-users-data/search |
❌ |
Plus rawRequest(SDKRequestOptions) as an escape hatch for endpoints not yet wrapped — it applies the same headers, appId injection and error handling.
Sessions and cookies
The browser SDK relies on withCredentials: true and lets the user agent store the HTTP-only a_s_b cookie. package:http has no cookie jar, so this SDK ships SessionStore: credentialed requests replay the jar as a Cookie header, and responses to those requests are scanned for Set-Cookie.
authix.session.hasSession; // signed in?
authix.session.sessionCookie; // raw a_s_b value
authix.session.setSessionCookie(saved); // restore on app start
authix.session.clearSession(); // force sign-out locally
Persist authix.session.sessionCookie yourself (e.g. flutter_secure_storage) and seed it on launch to survive restarts.
Flutter Web: the browser owns the cookie jar. Pass a BrowserClient with credentials enabled and leave SessionStore empty:
NeuctraAuthix(config, client: BrowserClient()..withCredentials = true);
Pagination
getUserData, getAllUsersFromApp and getAllUsersDataFromApp return cursor-paginated envelopes (success, totalFetched, hasMore, nextCursor, data). Pass an itemParser to get typed items instead of raw maps:
String? cursor;
do {
final page = await authix.getAllUsersFromApp(limit: 50, cursor: cursor);
print(page.totalFetched);
cursor = page.nextCursor;
} while (cursor != null);
Errors
Every failure is a NeuctraAuthixException with message, status and the decoded data:
| Case | status |
Helper |
|---|---|---|
| Missing required argument | 400 |
isValidationError |
| Timeout / offline / DNS | 0 |
isNetworkError |
| Rejected credentials | 401 / 403 |
isAuthError |
| Any other backend error | as returned | — |
checkUserSession() is the one method that never throws: any failure resolves to authenticated: false and clears the local cookie.
Differences from the TypeScript SDK
These are unavoidable platform differences, not behaviour changes:
logoutUserdoes not reload. The TS version callswindow.location.reload(). Here it clears the session and invokes the optionalonLoggedOutcallback so you control navigation.statusis never lost. The TSloginUserre-wraps its error into a plainError, discarding the HTTP status. Every method here throws the sameNeuctraAuthixException, sostatusalways survives.- GET requests really carry a body. Browsers drop bodies on
GET, so the TS SDK'sappIdinjection silently vanishes on read routes. Dart sends it, so app scoping holds everywhere. - No console logging. The TS
requestEmailVerificationOTPcallsconsole.error; this SDK never writes to stdout.
Known quirks (preserved from the TypeScript SDK)
Kept deliberately so both SDKs speak identically to the backend:
- Caller data overrides
appId. The request body is built as{appId, ...data}, so a record with its ownappIdkey wins.addUserDataflattens yourdatamap into the body, so avoidappIdanddataCategoryas field names. - The four global routes use POST for reads — the backend expects a body.
updateUseracceptspassword, bypassing thecurrentPasswordcheck thatchangePasswordenforces. PreferchangePassword.- Data routes are authorised by the API key alone (no session cookie). Treat
apiKeyas a secret: do not ship a key with global read/write scope inside a distributed mobile binary.
Development
dart pub get
dart analyze
dart test
Libraries
- neuctra_authix_dart_package
- Neuctra Authix — official Dart/Flutter SDK.