@askit/auth-sdk

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript

Client SDK for the ASK IT Auth Server — a lightweight, fully-typed TypeScript library that wraps the Auth Server REST API. It provides easy authentication flows (login, register, email verification, password reset) with automatic JWT token management and role helpers. v1.0.0 is the current stable version, released as a single package with no dependencies. Works in Node.js, browsers, and modern JavaScript runtimes. Key differentiators: ESM-only, built-in token storage, explicit error handling via AuthError class, and TypeScript-first design.

error Cannot find module '@askit/auth-sdk' or its corresponding type declarations.
cause Package not installed or TypeScript not configured to resolve scoped packages.
fix
Run npm install @askit/auth-sdk and ensure tsconfig.json includes "moduleResolution": "node" or "bundler".
error TypeError: (0 , _askit_auth_sdk.AskITAuth) is not a constructor
cause Using CommonJS require() on an ESM-only package.
fix
Change const AskITAuth = require('@askit/auth-sdk') to import { AskITAuth } from '@askit/auth-sdk'.
error Property 'login' does not exist on type 'typeof import("...")'.
cause Attempting to call AskITAuth.login as a static method instead of creating an instance.
fix
Create an instance first: const auth = new AskITAuth({ baseUrl: '...' }); then call auth.login(...).
gotcha After login, the JWT is stored in-memory by default. It is not persisted to localStorage or cookies automatically.
fix Manually call auth.setToken(token) with a stored token on app load, or implement your own persistence layer.
gotcha The baseUrl must not end with a trailing slash. The SDK does not normalize URLs.
fix Ensure the baseUrl does not end with '/'. Example: 'https://auth.askaihk.com', not 'https://auth.askaihk.com/'.
breaking In v1.0.0, the AuthError class was introduced. In the beta version, errors were plain Error objects.
fix Update to v1.0.0 and catch AuthError instead of Error for API errors.
deprecated The `askit-auth-sdk` package (without scope) is deprecated. Use `@askit/auth-sdk` instead.
fix Uninstall 'askit-auth-sdk' and install '@askit/auth-sdk'.
npm install askit-auth-sdk
yarn add askit-auth-sdk
pnpm add askit-auth-sdk

Creates an AskITAuth client, logs in with email/password, stores the JWT automatically, and retrieves the current user profile.

import { AskITAuth } from '@askit/auth-sdk';

const auth = new AskITAuth({
  baseUrl: 'https://auth.askaihk.com',
});

async function main() {
  const { token, user } = await auth.login({
    email: 'murphy.lai@askit.com.hk',
    password: 'myPassword123',
  });

  console.log(`Welcome, ${user.full_name}!`);
  console.log(`Role: ${user.role}`);

  const me = await auth.me();
  console.log(me.email);
}

main().catch(console.error);