Skip to content

Installation & Setup

Install and configure the Neuctra Authix SDK. You must provide appName, baseUrl, apiKey, and appId.

Install SDK

npm install @neuctra/authix

Environment Variables

Client code gets a publishable key (pk_live_…); server code gets a secret key (sk_live_…). Create both on the API Keys page of the dashboard. A secret key never goes in a variable that reaches the browser.

Terminal
# Client build — a publishable key is safe to expose
VITE_AUTHIX_APP_ID=your_app_id_here
VITE_AUTHIX_PUBLISHABLE_KEY=pk_live_xxxxxxxx_xxxxxxxxxxxxxxxx

# Server only — never commit this, never give it a VITE_ or NEXT_PUBLIC_ prefix
AUTHIX_APP_ID=your_app_id_here
AUTHIX_SECRET_KEY=sk_live_xxxxxxxx_xxxxxxxxxxxxxxxx

Initialize SDK

Create a single reusable instance for your application. In browser code it uses the publishable key, which reaches sign-in flows, app data reads and the signed-in user's own account.

TypeScript
1// authix.ts — browser or mobile code
2import { NeuctraAuthix } from "@neuctra/authix";
3
4export const authix = new NeuctraAuthix({
5  appName: "MyApp",
6  baseUrl: "https://server.authix.neuctra.com/api",
7  apiKey: import.meta.env.VITE_AUTHIX_PUBLISHABLE_KEY, // pk_live_…
8  appId: import.meta.env.VITE_AUTHIX_APP_ID,
9});

Next.js Setup

Admin work — listing users, writing app data, setting roles — needs a secret key. Keep this client in server components, route handlers, or server actions, and never import it into browser code.

TypeScript
1// lib/authix.server.ts
2import "server-only";
3import { NeuctraAuthix } from "@neuctra/authix";
4
5export const authixAdmin = new NeuctraAuthix({
6  baseUrl: process.env.NEXT_PUBLIC_AUTHIX_BASE_URL!,
7
8  apiKey: process.env.AUTHIX_SECRET_KEY!, // sk_live_… — server only
9  appId: process.env.AUTHIX_APP_ID!,
10});

Quick Start

TypeScript
1export const signup = (name, email, password) =>
2  authix.signupUser({ name, email, password });
3
4export const login = (email, password) =>
5  authix.loginUser({ email, password });
6
7export const checkSession = () =>
8  authix.checkUserSession();

Error Handling

SDK errors include message and optional status.

TypeScript
1try {
2  await authix.loginUser({ email, password });
3} catch (err) {
4  console.error(err?.message, err?.status);
5}

Production Notes

  • Auth routes use HTTP-only cookies (ensure proper CORS setup).
  • Set the app's allowed origins before using a publishable key from a browser (otherwise 403 ORIGINS_NOT_CONFIGURED).
  • A secret key has full account authority and belongs only on a trusted server; Authix refuses it from a browser (403 SECRET_KEY_IN_BROWSER).
  • A secret key can act on any user by id, so take the user id from a session your server has verified.
  • Validate inputs before calling SDK methods.

Next Steps

  • Authentication: signupUser, loginUser
  • Sessions: checkUserSession
  • User APIs: getUserProfile, updateUser (getUser needs a secret key)
  • Data APIs: addUserData, getAppData (addAppData needs a secret key)