JSPM

  • Created
  • Published
  • Downloads 28565
  • Score
    100M100P100Q146965F
  • License MIT

GoTrue API client for JavaScript

Package Exports

  • gotrue-js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gotrue-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

GoTrue JS Client

This is a JS library for GoTrue API.

It lets you signup and authenticate users and is a building block for constructing the UI for signups, password recovery, login and logout.

Usage

import GoTrue from 'gotrue-js'

const auth = new GoTrue();

auth.signup(email, password).then(
  (response) => console.log("Confirmation email sent"),
  (error) => console.log("Error during signup: %o", error.msg)
);

auth.confirm(token).then(
  (user) => console.log("Logged in as %s", user.email),
  (error) => console.log("Failed to log in: %o", error)
);

auth.login(email, password).then(
  (user) => console.log("Logged in as %s", user.email),
  (error) => console.log("Failed to log in: %o", error);
)

auth.requestPasswordRecovery(email).then(
  (response) => console.log("Recovery email sent"),
  (error) => console.log("Error sending recovery mail: %o", error)
);

auth.recover(token).then(
  (user) => console.log("Logged in as %s", user.email),
  (error) => console.log("Failed to verify recover token: %o", error)
);

const user = auth.currentUser()

user.update({email: newEmail, password: newPassword}).then(
  (user) => console.log("Updated user"),
  (error) => console.log("Failed to update user: %o", error)
);

user.jwt().then(
  (token) => console.log("Current token: %s", token),
  (error) => console.log("Failed to get token: %o", error)
);

user.logout().then(
  (response) => console.log("User logged out"),
  (error) => console.log("Failed to logout user: %o", error)
);