npm.io
0.0.22 • Published 5 years ago

feather-client-js

Licence
MIT
Version
0.0.22
Deps
2
Size
72 kB
Vulns
0
Weekly
0
Stars
4

Feather Client Javascript Library

npm

This library provides a convenient stateful interface to the Feather API for applications running in a Javascript client environment.

Have any questions? We're hanging out on Discord

Install

$ npm install feather-client-js --save
# or
$ yarn add feather-client-js

Usage

The Feather package must be initialized with your project's API key, available on the Feather Dashboard. Include the API key when you require the package:

import { FeatherClient } from "feather-client-js";

const feather = FeatherClient("YOUR_API_KEY");

To listen for changes to the authentication state:

const unsubscribe = feather.onStateChange(currentUser => {
  console.log(`The current user is: ${JSON.stringify(currentUser)}`);
});

unsubscribe();

To sign in:

feather
  .newCurrentCredential({
    email: "foo@example.com",
    password: "pa$w0rd"
  })
  .then(credential => {
    if (credential.status !== "valid")
      throw new Error("Email or password is incorrect.");
    return feather.newCurrentUser(credential.token);
  })
  .then(currentUser => console.log(currentUser))
  .catch(e => {
    // Handle errors
  });

To sign in anonymously:

feather
  .newCurrentUser()
  .then(currentUser => console.log(currentUser))
  .catch(e => {
    // Handle errors
  });

To sign out:

feather
  .currentUser()
  .then(currentUser => currentUser.revokeTokens())
  .catch(e => {
    // Handle errors
  });

Development

If you do not have yarn installed, you can install it with npm install --global yarn.

Run the tests:

$ yarn install
$ yarn test