• Public
  • Public/Protected
  • All



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.


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.

Generated using TypeDoc