@sensenet/authentication-jwt
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

@sensenet/authentication-jwt

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

NPM version NPM downloads License: GPL v2

Install

# Yarn
yarn add @sensenet/authentication-jwt

# NPM
npm install @sensenet/authentication-jwt

Setup and usage

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

  • sessionLifetime - You can change how user sessions should be persisted on the client, you can use 'session', which means the user will be logged out when the browser is closed, or 'expiration', in that case the token expiration property will be used. This behavior is implemented for JWT Authentication.

Service setup:

import { TokenPersist } from '@sensenet/authentication-jwt'

const repository = new Repository()
const jwtService = new JwtService(repository, { select: 'all' }, 5000, TokenPersist.Expiration)

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.

Package Sidebar

Install

npm i @sensenet/authentication-jwt

Homepage

sensenet.com

Weekly Downloads

4

Version

1.1.4

License

GPL-2.0

Unpacked Size

97.5 kB

Total Files

53

Last publish

Collaborators

  • hassanad
  • kubehu
  • herflis
  • tusmester
  • kavics
  • vargajoe