Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

@sensenet/authentication-jwt

1.0.6-alpha.0 • Public • Published

sn-authentication-jwt

Gitter chat Build Status codecov Greenkeeper badge NPM version NPM downloads License Commitizen friendly

This NPM package contains a client-side JWT authentication service implementation for sensenet.

Installation

npm install @sensenet/authentication-jwt

Setup and usage

You can use JWT authentication with a preconfigured sensenet >7.0.0 backend.

Service setup:

const repository = new Repository();
const jwtService = new JwtService(repository);

Login / logout:

You can log in and out using the following API endpoints:

const loginSuccess = await repository.authentication.login("username", "password");
const logoutSuccess = await repository.authentication.logout();

State and user changes

You can subscribe to authentication state and current user changes using the following two observable values:

jwtService.currentUser.subscribe((newUser) => {
    console.log("User changed. New user: ", newUser.LoginName);
});
 
jwtService.state.subscribe((newState) => {
    console.log("Authentication state changed to", newState);
});

Authenticated requests

Please note that if you want to send custom authenticated requests to the content repository, always use the repository.fetch(...) method. This ensures that your access token will be renewed if needed and your authentication state will consistent.

install

npm i @sensenet/authentication-jwt

Downloadsweekly downloads

68

version

1.0.6-alpha.0

license

GPL-2.0

homepage

sensenet.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability