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

@infinity-frame/infinityuser-client

v1.0.0

Published

Simple user management system with JWT authentication

Downloads

4

Readme

InfinityUser client

This package provides utility functions for authentication using refresh tokens and JWT (JSON Web Tokens). It supports basic authentication functionalities such as registering users, logging in, logging out, changing email, and refreshing tokens.

Installation

You can install this package using npm:

npm install infinity-user-client

Usage

Import the required functions from the package:

import {
  authFetch,
  initAuth,
  register,
  trySignInWithRefreshToken,
  logout,
  changeEmail,
  login,
} from "auth-utility-package";

Functions

initAuth({ authApiPath })

Initializes the authentication utility with the API path for authentication.

  • Parameters:
    • authApiPath (string): The base URL path for the authentication API.
  • Returns:
    • An authentication object containing necessary properties for subsequent operations.

Example

const auth = initAuth({ authApiPath: "https://your-auth-api.com" });

register(auth, email, password)

Registers a new user with the provided email and password.

  • Parameters:
    • auth (object): The authentication object initialized with initAuth().
    • email (string): The email of the user to be registered.
    • password (string): The password for the new user.
  • Returns:
    • A user object upon successful registration.

Example

const newUser = await register(auth, "[email protected]", "password123");

login(auth, email, password)

Logs in a user with the provided email and password.

  • Parameters:
    • auth (object): The authentication object initialized with initAuth().
    • email (string): The email of the user to log in.
    • password (string): The password for the user.
  • Returns:
    • A user object upon successful login.

Example

const user = await login(auth, "[email protected]", "password123");

logout(auth)

Logs out the currently authenticated user.

  • Parameters:
    • auth (object): The authentication object initialized with initAuth().
  • Returns:
    • No return value.

Example

await logout(auth);

changeEmail(auth, email, password)

Changes the email address of the currently authenticated user.

  • Parameters:
    • auth (object): The authentication object initialized with initAuth().
    • email (string): The new email address.
    • password (string): The user's current password.
  • Returns:
    • The updated user object.

Example

const updatedUser = await changeEmail(auth, "[email protected]", "oldpassword");

authFetch(auth, path, data)

A helper function for authenticated API requests. Automatically handles token refreshing if necessary.

  • Parameters:
    • auth (object): The authentication object initialized with initAuth().
    • path (string): The API endpoint URL.
    • data (object): Optional data object containing request parameters such as method, headers, and body.
  • Returns:
    • The fetch response object.

Example

const response = await authFetch(auth, "/api/data", {
  method: "GET",
});
const responseData = await response.json();

trySignInWithRefreshToken(auth)

Attempts to sign in using a refresh token if available.

  • Parameters:
    • auth (object): The authentication object initialized with initAuth().
  • Returns:
    • The user object upon successful sign-in using the refresh token, or null if no refresh token is available or user is already signed in.

Example

const user = await trySignInWithRefreshToken(auth);

changePassword(auth, oldPassword, newPassword)

Changes the password of the currently authenticated user.

  • Parameters:
    • auth (object): The authentication object initialized with initAuth().
    • oldPassword (string): The user's current password.
    • newPassword (string): The new password.
  • Returns:
    • The updated user object.

Notes

  • Make sure to handle errors appropriately using try-catch blocks around these functions to catch any thrown errors.
  • Each function requires an initialized auth object created using initAuth() to operate correctly.
  • Ensure to configure and handle authentication API endpoints properly based on your backend implementation.

This package simplifies the process of authentication in your application by encapsulating common authentication operations.