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

@mkwebdev/react-authjs-library

v0.0.2

Published

A simple and flexible authentication library for React applications, built on top of NextAuth.js.

Downloads

19

Readme

React AuthJS Library

A simple and flexible authentication library for React applications, built on top of NextAuth.js.

Installation

To install the React AuthJS Library, run the following command in your project directory:

npm install react-authjs-library

Usage

1. Wrap your application with AuthProvider

First, wrap your main application component with the AuthProvider:

import { AuthProvider } from 'react-authjs-library';

function App() {
  return (
    <AuthProvider>
      {/* Your app components */}
    </AuthProvider>
  );
}

2. Use authentication components

The library provides several components and hooks for managing authentication:

SignInButton

import { SignInButton } from 'react-authjs-library';

function LoginPage() {
  return (
    <div>
      <h1>Login</h1>
      <SignInButton />
    </div>
  );
}

SignOutButton

import { SignOutButton } from 'react-authjs-library';

function Dashboard() {
  return (
    <div>
      <h1>Dashboard</h1>
      <SignOutButton />
    </div>
  );
}

ProtectedRoute

Wrap components that require authentication with ProtectedRoute:

import { ProtectedRoute } from 'react-authjs-library';

function PrivateContent() {
  return (
    <ProtectedRoute>
      <h2>This content is only visible to authenticated users</h2>
    </ProtectedRoute>
  );
}

3. Access authentication state

Use the useAuth hook to access the current authentication state:

import { useAuth } from 'react-authjs-library';

function UserProfile() {
  const { user, isAuthenticated, isLoading } = useAuth();

  if (isLoading) return <div>Loading...</div>;
  if (!isAuthenticated) return <div>Please sign in</div>;

  return (
    <div>
      <h1>Welcome, {user.name}!</h1>
      {/* Display user profile information */}
    </div>
  );
}

Configuration

To configure the authentication providers and options, you need to set up NextAuth.js in your project. Refer to the NextAuth.js documentation for detailed instructions on how to configure various authentication providers.

Important Notes

  1. This library is a wrapper around NextAuth.js, so you'll need to configure NextAuth.js separately in your project.
  2. Ensure you have the necessary backend setup to handle authentication requests.
  3. The current implementation is designed for client-side usage. For server-side rendering or more advanced configurations, refer to the NextAuth.js documentation.

Customization

You can customize the appearance of the SignInButton and SignOutButton components by passing a className prop:

<SignInButton className="my-custom-button-class" />
<SignOutButton className="my-custom-button-class" />

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.