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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ackee/petrus

v7.0.0

Published

A tool for handling token-based authentication in React/Redux/Redux-Saga applications

Downloads

198

Readme

ackee|Petrus

GitHub license bundlephobia

Petrus

A tool for handling token-based authentication in react, redux, redux-saga applications.

It automatically refreshes an access token based on provided expiration timestamp, persists state, so the authentication session can last longer.


Table of contents


Installation

$ yarn add @ackee/petrus

Stack Dependencies

@ackee/petrus requires a following peer dependencies:

 "core-js": "3.x",
 "react": "16.x | 17.x | 18.x",
 "react-redux": "7.x | 8.x",
 "redux": "4.x",
 "redux-saga": "1.x"

Usage examples

Authentication flows

  1. Direct authentication (with password)

    • Basic config
      • Obtaining tokens with authenticate method by sending credentials to an endpoint from loginRequest Redux action.
      • Fetching authorized user with getAuthUser method.
      • Automatically refreshing accessToken based on provided expiration prop.
      • Tokens and auth. user local persistence in IndexedDB.
      • Using custom TS types for auth user, tokens, and credentials.
  2. Federated authentication (with a token)

    • OAuth 2.0 – Authorization Code Flow

      What's an authorization code flow?

      • The front channel flow is used by the client application to obtain an authorization code grant.
      • The back channel is used by the client application to exchange the authorization code grant for an access token (and optionally a refresh token).
      • High security flow.
    • OAuth 2.0 – Implicit Flow

      What's an implicit flow?

      • An access token is returned directly from the authorization request (front channel only). It typically does not support refresh tokens.
      • This flow is also called 2 Legged OAuth.
      • Low security by default, make sure to follow at least these security rules.

    Of course, you can choose from any other numerous flows available. Learn more about OAuth flows in "What the heck is OAuth?" article.

Other examples

  1. Usage with @ackee/antonio API client