Ankhem Auth

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

Ankhem Auth is a minimal authentication component for JavaScript/TypeScript applications, part of the Ankhem ecosystem. Current stable version 0.0.25. Released irregularly as a pre-1.0 package. It provides basic auth utilities (login, logout, token management) with a small API surface. Differentiators: zero-dependency design (except Ankhem core), simple token storage abstraction, and TypeScript definitions included. Not recommended for production without careful review due to early stage.

error TypeError: Cannot destructure property 'storage' of 'undefined' as it is undefined.
cause Auth constructor called without an argument (e.g., new Auth()).
fix
Call new Auth({ storage: localStorage, tokenKey: 'token' }) with options object.
error Uncaught TypeError: auth.login is not a function
cause Using default import in a way that resolves to the Auth class itself, but attempting to call without instantiating.
fix
Instantiate Auth first: const auth = new Auth(config); then auth.login(...).
error Property 'user' does not exist on type 'string'
cause Assuming login returns a string after version 0.0.20, which returns an object.
fix
Update TypeScript types: use response.user or response.token.
gotcha Auth constructor expects an object with storage and tokenKey; if not provided, defaults to in-memory storage, which loses tokens on page refresh in browser.
fix Always pass a persistent storage like localStorage as shown in quickstart.
breaking Version 0.0.20 changed login() return type from Promise<string> to Promise<{ user: any; token: string }>.
fix Update code to expect an object instead of a string: response.token vs response.
deprecated Method setToken() deprecated since 0.0.22; use updateToken() instead.
fix Replace setToken() calls with updateToken() with same arguments.
npm install ankhem-auth
yarn add ankhem-auth
pnpm add ankhem-auth

Creates an Auth instance, logs in with credentials, logs out, and retrieves the current token.

import { Auth } from 'ankhem-auth';

const auth = new Auth({
  storage: localStorage,
  tokenKey: 'myapp_token'
});

auth.login({ username: 'user', password: 'pass' }).then(user => {
  console.log('Logged in', user);
}).catch(err => console.error(err));

auth.logout();

const token = auth.getToken();