npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

virava

v1.7.1

Published

The aim of this package is to enclose the auth logic for the most common case and give the user a simple flow for doing authentication.

Readme

Virava

Virava is a lightweight service designed to handle authentication inside a web application.

Dependencies

Getting started with Virava

This guide explains how to set up your project to begin using Virava. It includes information on prerequisites, installing and configuring Virava.

1. Install Virava

To install Virava you will need to have npm previously installed and then type in a terminal:

npm install virava

This will add project dependencies to package.json.

2. Usage

Virava currently supports 2 ways of handling authentication depending on the API used. One uses Keycloak and its default flow. The other - a custom Backend REST API.

All of them share similar approach. It is recommended to use the factory class to instantiate the Virava. Depending on the flow you are using you should cast the service instantiated so you can get additional/correct methods.

  • Keycloak approach:
import { AuthServiceFactory, ServiceType, KeycloakServiceDefault } from 'virava';

const authService = AuthServiceFactory.create(ServiceType.DEFAULT) as KeycloakServiceDefault;

Then you will need to add the configuration and the initOptions for the service (again depending on the flow). The initOptions is an optional parameter (defaults to { useNonce: true }).

import { KeycloakConfigDefault, KeycloakInitOptions } from 'virava';

const config: KeycloakConfigDefault = {
  clientId:'',
  baseUrl: '',
  realm: '',
  tokenStorageKey: '', //optional
  refreshTokenStorageKey: '', //optional
  expirationDateStorageKey: '', //optional
  expirationRefreshDateStorageKey: '', //optional
  redirectUri: '' //optional
};

const initOptions: KeycloakInitOptions = {
  // Add your desired init options here
};

authService.init(config, initOptions);
  • Custom approach:
import { AuthServiceFactory, ServiceType, KeycloakServiceCustom } from 'virava';

const authService = AuthServiceFactory.create(ServiceType.CUSTOM) as KeycloakServiceCustom;

Then you will need to add the configuration for the service (again depending on the flow).

import { KeycloakConfigCustom } from 'virava';

const config: KeycloakConfigCustom = {
  clientId: '',
  baseUrl: '',
  realm: '',
  tokenStorageKey: '', //optional
  refreshTokenStorageKey: '', //optional
  expirationDateStorageKey: '', //optional
  expirationRefreshDateStorageKey: '', //optional
  gatewayBaseUrl: ''
};

authService.init(config);

3. Start using Virava

To start using Virava simply import your instance of authService and trigger some of its methods:

  • Keycloak Default pages approach:
/**
 * Initializes the auth service configuration. It returns Promise.
 */
authService.init(configuration, initOptions);

/**
 * Redirects the user to the keycloak login page. It returns Promise.
 */
authService.login();

/**
 * Redirects the user to the register page. It returns Promise.
 */
authService.register(email, password, confirmPassword);

/**
 * Checks if the user is authenticated, returning a boolean.
 */
authService.isAuthenticated();

/**
 * Checks if the refresh token has expired, returning a boolean.
 */
authService.isRefreshTokenExpired();

/**
 * Checks if the access token has expired, returning a boolean.
 */
authService.isAccessTokenExpired();

/**
 * Updates the authentication tokens in localStorage upon successful refresh. It returns Promise.
 */
authService.updateToken();

/**
 * Checks if the user has a specific role for a resource or client, returning a boolean.
 */
authService.hasResourceRole(roleName, resource);

/**
 * Checks if the user has a specific role in the realm, returning a boolean.
 */
authService.hasRealmRole(roleName);

/**
 * Logouts user and remove tokens from `localStorage`. It returns Promise.
 */
authService.logout();

/**
 * Returns the raw access token string from `localStorage`
 */
authService.getAccessTokenRaw();

/**
 * Returns the parsed access token from `localStorage`; optionally scoped to type T
 */
authService.getAccessTokenRaw<T>();
  • Keycloak Custom pages approach:
/**
 * Initializes the auth service configuration.
 */
authService.init(configuration);

/**
 * This method is designed to work with Direct Access Grant flow of OAuth. It returns Promise.
 */
authService.login(username, password);

/**
 * This method registers the user. It returns Promise.
 */
authService.register(email, password, confirmPassword);

/**
 * This method resets user's password. It returns Promise.
 */
authService.resetPassword(email);

/**
 * This method changes the user's password. It returns Promise.
 */
authService.changePassword(email, currentPassword, newPassword, confirmPassword);

/**
 * This method refreshes the token and sets the new ones in `localStorage`. It returns Promise.
 */
authService.refreshToken();

/**
 * Logouts user and remove tokens from `localStorage`. It returns Promise.
 */
authService.logout();

/**
 * Returns the raw access token string from `localStorage`
 */
authService.getAccessTokenRaw();

/**
 * Returns the parsed access token from `localStorage`; optionally scoped to type T
 */
authService.getAccessTokenRaw<T>();

4. Test your application

Run your local dev server:

  • in React:
npm start
  • in Angular
ng serve

Examples

Angular using the default flow (Keycloak)

Location: examples/angular-default

Angular using the custom flow

Location: examples/angular

React using the custom flow

Location: examples/react