{"id":16918,"library":"township-client","title":"Township Auth Client","description":"township-client is a client-side JavaScript library designed to interact with Township authentication servers. It enables common user credential management operations such as registration, login, logout, and password changes. The library, currently at version 1.3.2, appears to have ceased active development around 2017, aligning with the last known activity on its companion `township` server project. Key features include the ability to manage user credentials across multiple Township servers, automatic persistence of login information to a configuration file (or `localStorage` in browsers), and a wrapper for making authenticated requests (`secureRequest`). This client primarily targets CommonJS environments, as suggested by its `require()`-based examples. Due to its age, it might not integrate seamlessly with modern ESM-first projects and relies on older dependency versions.","status":"abandoned","version":"1.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/township/township-client","tags":["javascript"],"install":[{"cmd":"npm install township-client","lang":"bash","label":"npm"},{"cmd":"yarn add township-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add township-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for making HTTP requests to the Township server, as indicated by the 'request function' link in the README.","package":"nets","optional":false}],"imports":[{"note":"The library is primarily designed for CommonJS (`require`) environments. While ES Module imports might work with transpilers or `esModuleInterop`, the original intent is CJS.","wrong":"import TownshipClient from 'township-client'","symbol":"TownshipClient","correct":"const TownshipClient = require('township-client')"},{"note":"Registers a new user with the specified email and password, receiving a token upon success.","symbol":"client.register","correct":"client.register({ email: '...', password: '...' }, callback)"},{"note":"Logs in an existing user with the provided credentials, persisting login information to the configured file or localStorage.","symbol":"client.login","correct":"client.login({ email: '...', password: '...' }, callback)"}],"quickstart":{"code":"const TownshipClient = require('township-client');\n\nconst client = TownshipClient({\n  server: 'https://api.township.site', // Set default server on init\n  config: {\n    filename: '.townshiprc' \n    // config file stored in user homedir. \n    // uses localstorage if in browser\n  }\n});\n\nclient.register({\n  email: 'joe@hand.email',\n  password: 'Iheartcoffee'\n}, function (err, res, body) {\n  if (err) return console.error('Register error', err);\n  console.log('Registered successfully with ', body.key, body.token);\n\n  client.login({\n    email: 'joe@hand.email',\n    password: 'Iheartcoffee'\n  }, function (err, res, body) {\n    if (err) return console.error('Login error', err);\n    console.log('Logged in successfully!');\n    console.log('User login info:', client.getLogin());\n  });\n});","lang":"javascript","description":"Initializes the TownshipClient, registers a new user with example credentials, and then attempts to log that user in, demonstrating the basic authentication flow and login persistence."},"warnings":[{"fix":"Consider migrating to a actively maintained authentication solution. Using this library in new projects is not recommended due to unaddressed security vulnerabilities and lack of support.","message":"The `township-client` library and its associated `township` server project appear to be abandoned, with no significant development activity since around 2017. This implies no further updates, bug fixes, or security patches will be provided.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Audit project dependencies for known CVEs. If external audits are not feasible, consider wrapping the library's network calls with a more modern and secure HTTP client, or migrating away from this library entirely.","message":"The library relies on outdated versions of underlying HTTP clients (like `nets`), which may contain known security vulnerabilities, lack modern features, or have performance issues compared to contemporary alternatives.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If using in an ESM project, explicitly configure your build tools (like Webpack, Rollup, or TypeScript compiler) to handle CommonJS modules, or use dynamic `import()` for the module.","message":"Primarily designed for CommonJS (`require`) environments, integrating this library into modern ES Module (`import`) projects might require specific build configurations (e.g., `esModuleInterop` in TypeScript) or result in compatibility issues.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually create a `township-client.d.ts` file with basic type declarations for the `TownshipClient` constructor and its methods, or use `@ts-ignore` for untyped imports (not recommended for production).","message":"The library does not ship with TypeScript type definitions. Developers using TypeScript will need to create their own declaration files (`.d.ts`) to achieve type safety or use it as a dynamically imported JavaScript module.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"For CommonJS, use `const TownshipClient = require('township-client'); const client = TownshipClient(...)`. If using ESM, and if the package has a default export compatible with `esModuleInterop`, `import TownshipClient from 'township-client'` might work, otherwise `import * as TownshipClient from 'township-client'; const client = TownshipClient.default(...)` may be necessary.","cause":"Attempting to instantiate `TownshipClient` when it's not correctly imported as a constructor, often due to mismatched CommonJS/ESM import styles or transpilation issues.","error":"TypeError: TownshipClient is not a constructor"},{"fix":"Verify that the `server` URL passed to `TownshipClient` initialization is correct and the target Township authentication server is operational and accessible from the client's network environment.","cause":"The configured `opts.server` URL is incorrect, the Township server is unreachable, or there is a general network connectivity issue.","error":"Error: Server connection failed"},{"fix":"Use a unique email address for new user registration or attempt to log in if the user is already expected to exist.","cause":"An attempt was made to register a user with an email address that is already associated with an existing account on the Township server.","error":"Register error Error: {\"message\":\"email already exists\"}"},{"fix":"Double-check the email and password for typos. If the password is forgotten, the library's `changePassword` method can be used, but requires a valid login token for the user already to be saved.","cause":"The provided email or password for login does not match any registered user on the configured Township server.","error":"Login error Error: {\"message\":\"Invalid credentials\"}"}],"ecosystem":"npm","meta_description":null}