{"id":18113,"library":"ankhem-auth","title":"Ankhem Auth","description":"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.","status":"active","version":"0.0.25","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install ankhem-auth","lang":"bash","label":"npm"},{"cmd":"yarn add ankhem-auth","lang":"bash","label":"yarn"},{"cmd":"pnpm add ankhem-auth","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; CommonJS require() may not work depending on bundler configuration.","wrong":"const Auth = require('ankhem-auth').Auth","symbol":"Auth","correct":"import { Auth } from 'ankhem-auth'"},{"note":"Default export is the same as named Auth export. Both work identically.","wrong":"","symbol":"default","correct":"import Auth from 'ankhem-auth'"},{"note":"Additional interface exported for custom token storage implementations.","wrong":"","symbol":"TokenStorage","correct":"import { TokenStorage } from 'ankhem-auth'"}],"quickstart":{"code":"import { Auth } from 'ankhem-auth';\n\nconst auth = new Auth({\n  storage: localStorage,\n  tokenKey: 'myapp_token'\n});\n\nauth.login({ username: 'user', password: 'pass' }).then(user => {\n  console.log('Logged in', user);\n}).catch(err => console.error(err));\n\nauth.logout();\n\nconst token = auth.getToken();","lang":"typescript","description":"Creates an Auth instance, logs in with credentials, logs out, and retrieves the current token."},"warnings":[{"fix":"Always pass a persistent storage like localStorage as shown in quickstart.","message":"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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Update code to expect an object instead of a string: response.token vs response.","message":"Version 0.0.20 changed login() return type from Promise<string> to Promise<{ user: any; token: string }>.","severity":"breaking","affected_versions":">=0.0.20"},{"fix":"Replace setToken() calls with updateToken() with same arguments.","message":"Method setToken() deprecated since 0.0.22; use updateToken() instead.","severity":"deprecated","affected_versions":">=0.0.22"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Call new Auth({ storage: localStorage, tokenKey: 'token' }) with options object.","cause":"Auth constructor called without an argument (e.g., new Auth()).","error":"TypeError: Cannot destructure property 'storage' of 'undefined' as it is undefined."},{"fix":"Instantiate Auth first: const auth = new Auth(config); then auth.login(...).","cause":"Using default import in a way that resolves to the Auth class itself, but attempting to call without instantiating.","error":"Uncaught TypeError: auth.login is not a function"},{"fix":"Update TypeScript types: use response.user or response.token.","cause":"Assuming login returns a string after version 0.0.20, which returns an object.","error":"Property 'user' does not exist on type 'string'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}