feather-client-js

0.0.22 • Public • Published

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

Package Sidebar

Install

npm i feather-client-js

Weekly Downloads

0

Version

0.0.22

License

MIT

Unpacked Size

74.2 kB

Total Files

32

Last publish

Collaborators

  • feather-id