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

@kobbleio/react

v1.4.0

Published

Add authentication and monetization to your React application in minutes using Kobble

Downloads

19

Readme

Add authentication and monetization to your React application in minutes using Kobble

License Status

This package helps you add authentication to your React Application with Kobble Auth SDK in a few minutes.

It's secure by design (using PKCE flow) and easy to use.

Getting Started

Installation

Using npm in your project directory run the following command:

npm install @kobbleio/react

Configure Kobble

Create an Application in your Kobble Dashboard.

Make sure your application can handle your localhost callback URL (see section below).

Note the Client ID and your Portal Domain values.

Visit our Quick Start Guide to learn more.

Usage

Kobble requires your app to be wrapped in a KobbleProvider component. This component should be at the root of your application.

import ReactDOM from 'react-dom/client';
import { KobbleProvider, SignedIn, SignedOut } from "@kobbleio/react";

render(
  <KobbleProvider
    domain={import.meta.env.VITE_KOBBLE_DOMAIN!}
    clientId={import.meta.env.VITE_KOBBLE_CLIENT_ID!}
    redirectUri={import.meta.env.VITE_KOBBLE_REDIRECT_URI!}
  >
    <App />
  </KobbleProvider>,
  document.getElementById('root'),
);

function App() {
  return (
    <>
      <h1>Hello World!</h1>
      <SignedIn>
        <p>This is only visible for signed in users.</p>
      </SignedIn>
      
      <SignedOut>
        <p>This is only visible for unauthenticated users.</p>
      </SignedOut>
    </>
  );
}

Utility Components

The package provides various utility components to help you manage the user's authentication status.

  • <SignedIn />: Only shows its children if the user is signed in.
  • <SignedOut />: Only shows its children if the user is signed out.
  • <LoginButton />: A button that triggers the login flow. I can be customized by passing a child prop.
  • <LogoutButton />: A button that triggers the logout flow. I can be customized by passing a child prop.
  • <HandleCallback />: A component that handles the authentication callback for the PKCE flow.
  • <PortalLink />: A link that redirects to your Customer Portal.
  • <PricingLink />: A link that redirects to your Pricing Page.
  • <ProfileLink />: A link that redirects to the user's profile page.

Utility Hooks

The package provides some hooks to access the user's authentication status and Kobble Client.

  • useAuth(): Returns the user's authentication status and the Kobble Client.
  • useAuthStateChanged(callback): Calls the callback function when the user's authentication status changes.
  • useKobble(): Returns the Kobble Client instance (which uses Kobble SPA SDK).

Examples

import { LoginButton, LogoutButton } from "@kobbleio/react";

const MyPage = () => {
  const { user } = useAuth();

  return (
    <>
      <SignedIn>
        <h1>Hello {user.name}</h1>
        <LogoutButton />
      </SignedIn>

      <SignedOut>
        <LoginButton />
      </SignedOut>
    </>
  )
}

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.


What is Kobble?