Skip to content

Authentication

Bazaar provides authentication out-of-the-box allowing you to create and authenticate users securely and easily.

Authorization is provided with the Permissions API.

Log in and Sign up are conveniently combined into a single method call:

bzr.login();

Calling the login method opens a pop-up window by default, which falls back to redirect login if the pop-up fails to open.

Optionally, you can set a login type:

import { LoginType } from "@bzr/bazaar";
bzr.login({ type: LoginType.REDIRECT });

Available LoginType are

  • POPUP_FALLBACK: Complete auth in a popup window but fall back to redirect if popup creation fails (default).
  • POPUP: Complete auth in a popup window.
  • REDIRECT: Complete auth via a redirect. This may case the site to loose context (temporary, unsaved data).

A utility method to delete an auth token from local storage and perform a page refresh.

bzr.logOut();

A utility method to check if an auth token is set in local storage.

bzr.isLoggedIn();

Logging in takes place without a page fresh, so you need a way to handle a successful login event. To do so, set a callback as the first and only argument of onLogin:

bzr.onLogin(() => {
// Handle user log in
// e.g. Set local state and redirect
});

Handle a login error event:

bzr.onLoginError(() => {
// Handle log in error
// e.g. Show error message
});