feather-client-js
v0.0.22
Published
Javascript library for the Feather API
Downloads
18
Maintainers
Readme
Feather Client Javascript Library
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: "[email protected]",
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