Township Auth Client

1.3.2 · abandoned · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

const TownshipClient = require('township-client');

const client = TownshipClient({
  server: 'https://api.township.site', // Set default server on init
  config: {
    filename: '.townshiprc' 
    // config file stored in user homedir. 
    // uses localstorage if in browser
  }
});

client.register({
  email: 'joe@hand.email',
  password: 'Iheartcoffee'
}, function (err, res, body) {
  if (err) return console.error('Register error', err);
  console.log('Registered successfully with ', body.key, body.token);

  client.login({
    email: 'joe@hand.email',
    password: 'Iheartcoffee'
  }, function (err, res, body) {
    if (err) return console.error('Login error', err);
    console.log('Logged in successfully!');
    console.log('User login info:', client.getLogin());
  });
});

view raw JSON →