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

@rfrsh/auth-library

v1.0.31

Published

**@rfrsh/auth-library** is a powerful authentication service package designed to provide secure authentication and user management functionalities. It includes classes for handling user authentication, user data storage, and user context management.

Downloads

36

Readme

@rfrsh/auth-library

@rfrsh/auth-library is a powerful authentication service package designed to provide secure authentication and user management functionalities. It includes classes for handling user authentication, user data storage, and user context management.

Installation

npm install @rfrsh/auth-library

OR

yarn add @rfrsh/auth-library

Usage

To use the @rfrsh/auth-library package in your project, import the necessary classes and set up the required configurations. Here's a basic example of how to use the package:

AuthController

To use the @rfrsh/auth-library package in your project, you can create an instance of AuthController and interact with it to perform various authentication-related operations. Here's an example of how to use the AuthController class:

// Import the necessary modules
import AuthController, { WalletContextState } from '@rfrsh/auth-library';

// Initialize the AuthController with the URL of the authentication service
const authController = new AuthController("https://auth-service.rfrsh.io");

// Function to handle login using the connected Solana wallet
const handleLogin = async (wallet: WalletContextState, isTx: boolean = false) => {
  try {
    // Perform the login operation using the AuthController
    await authController.login(wallet, solanaConnection, isTx);

    // Login successful, perform actions accordingly
    console.log("Login successful!");
    console.log("User:", authController.user);
    console.log("Wallets:", authController.wallets);
  } catch (error) {
    // Handle login errors
    console.error("Login failed:", error.message);
  }
};

// Function to handle logout
const handleLogout = async () => {
  try {
    // Perform the logout operation using the AuthController
    await authController.logout();

    // Logout successful, perform actions accordingly
    console.log("Logged out successfully!");
  } catch (error) {
    // Handle logout errors
    console.error("Logout failed:", error.message);
  }
};

// Function to handle adding a new wallet to the user's account
const handleAddWallet = async (wallet: WalletContextState, isTx: boolean = false) => {
  try {
    // Perform the addWallet operation using the AuthController
    await authController.addWallet(wallet, isTx);

    // Wallet addition successful, perform actions accordingly
    console.log("Wallet added successfully!");
    console.log("Updated Wallets:", authController.wallets);
  } catch (error) {
    // Handle addWallet errors
    console.error("Failed to add wallet:", error.message);
  }
};

// Function to handle removing a wallet from the user's account
const handleRemoveWallet = async (walletAddress: string) => {
  try {
    // Perform the removeWallet operation using the AuthController
    await authController.removeWallet(walletAddress);

    // Wallet removal successful, perform actions accordingly
    console.log("Wallet removed successfully!");
    console.log("Updated Wallets:", authController.wallets);
  } catch (error) {
    // Handle removeWallet errors
    console.error("Failed to remove wallet:", error.message);
  }
};

AppService

To interact with the application data, you can use the AppService class. You can fetch app details from the database, get the endpoint URL, access token secret, and fetch user data associated with the app. Here's an example of how to use the AppService class:

import { AppService } from '@rfrsh/auth-library';

// Fetch the app service instance with a custom API endpoint.
const appService = AppService.fetch('https://app-service.example.com');

// Fetch an application from the database using its API key and create a new App instance.
const app = await appService.fetchApp('your-api-key');

// Get the endpoint URL for the app.
const endpoint = app.endpoint;

// Get the Access Token Secret for the app.
const accessTokenSecret = app.accessTokenSecret;

// Fetch a user associated with the app from the database or the cache.
const user = await app.user('user123', true); // Set to true to refetch the user from the database.

User

The UserService class allows you to interact with user data and context management. You can fetch the user's context data from the Redis cache storage and set a new context for the user. Here's an example of how to use the User class:

// Get the user's ID.
const userID = user.id;

// Get the user's information.
const userInfo = user.info;

// Fetch the user's context from the Redis cache storage.
const context = await user.getContext();

// Set the user's context in the Redis cache storage.
const updatedContext = await user.setContext({ theme: 'dark' });

Store and MemoryStore

You can use the Store and MemoryStore classes to store data in memory or create a custom data store. Here's an example of how to use the Store and MemoryStore classes:

import { Store, MemoryStore } from '@rfrsh/auth-library';

// Create a new custom data store extending the Store class.
class CustomStore extends Store<number> {
  // Implement the required methods: get, set, and delete.
}

// Use the default in-memory data store implementation.
const memoryStore = new MemoryStore<string>();

// Set a value in the data store.
memoryStore.set('key1', 'value1');

// Get a value from the data store.
const value = memoryStore.get('key1'); // Returns 'value1'

// Delete a value from the data store.
memoryStore.delete('key1');

Features

  • User Registration: Register new users with their details and associate a Solana wallet with their account.

  • User Login: Allow existing users to log in using their connected Solana wallet.

  • Access Token Management: Obtain and refresh access tokens for authenticated users.

  • User Context: Manage user context data stored in the Redis cache storage.

  • Wallet Management: Add or remove Solana wallets associated with user accounts.

API Documentation

For detailed API documentation and usage instructions, please refer to the API Documentation for this package.

License

This package is released under the MIT License.

Contributions

Contributions to the @rfrsh/auth-library package are welcome! If you find any bugs or want to suggest new features, feel free to open an issue or submit a pull request on the GitHub repository. Your feedback and contributions will help make this package even better!