@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.
Common errors
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(...). Warnings
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'.
Install
npm install askit-auth-sdk yarn add askit-auth-sdk pnpm add askit-auth-sdk Imports
- AskITAuth wrong
const AskITAuth = require('@askit/auth-sdk')correctimport { AskITAuth } from '@askit/auth-sdk' - AuthError wrong
import AuthError from '@askit/auth-sdk'correctimport { AuthError } from '@askit/auth-sdk' - AskITAuth (type) wrong
import { AskITAuth } from '@askit/auth-sdk' // if only type neededcorrectimport type { AskITAuth } from '@askit/auth-sdk' - AuthUser (type) wrong
const AuthUser = require('@askit/auth-sdk').AuthUsercorrectimport type { AuthUser } from '@askit/auth-sdk'
Quickstart
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);