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

@strivacity/sdk-react

v1.0.0

Published

Strivacity React SDK client

Downloads

70

Readme

@strivacity/sdk-react

The SDK supports React version 16 and above

Install

npm install @strivacity/sdk-react

Usage

Wrap your app with Auth Provider:

import { AuthProvider, useStrivacity } from '@strivacity/sdk-react';

const sdkOptions = {
	mode: 'redirect',
	issuer: 'https://<YOUR_DOMAIN>',
	scopes: ['openid', 'profile'],
	clientId: '<YOUR_CLIENT_ID>',
	redirectUri: '<YOUR_REDIRECT_URI>',
};
const AppRoot = () => {
	return (
		<AuthProvider options={sdkOptions}>
			<App />
		</AuthProvider>
	);
};

How to use the SDK in your components:

import { useEffect, useCallback } from 'react'
import { useStrivacity } from '@strivacity/sdk-react';

const { isAuthenticated, idTokenClaims, login, logout } = useStrivacity();
const [name, setName] = useState('');
const onLogin = useCallback(() => {
	login();
},[]);
const onLogout = useCallback(() => {
	logout();
},[]);

useEffect(() => {
	setName(`${idTokenClaims?.given_name} ${idTokenClaims?.family_name}`);
}, [isAuthenticated, idTokenClaims]);

return (
	{isAuthenticated ? (<>
		<div>Welcome, {{ name }}!</div>
		<button onClick={onLogout()}>Logout</button>
	</>) : <>
		<div>Not logged in</div>
		<button onClick={onLogin()}>Log in</button>
	</>}
)

API Documentation

useStrivacity hook

useStrivacity<T extends PopupContext | RedirectContext>(): T;

You can choose between PopupContext or RedirectContext with the mode option when you configure the sdk options.

Properties

  • loading: boolean: Indicates if the session is being loaded.
  • isAuthenticated: boolean: Indicates whether the user is authenticated.
  • idTokenClaims: IdTokenClaims | null: Claims from the ID token or null if not available.
  • accessToken: string | null: The access token or null if not available.
  • refreshToken: string | null: The refresh token or null if not available.
  • accessTokenExpired: boolean: Indicates if the access token has expired.
  • accessTokenExpirationDate: number | null: Expiration date of the access token or null if not set.

Type: RedirectContext Represents the available methods for Redirect-based interactions.

  • login(options?: LoginOptions): Promise<void>: Initiates the login process by redirecting the user to the identity provider.
    • options (optional): Configuration options for login.
  • register(options?: RegisterOptions): Promise<void>: Registers a new user using a redirect flow.
    • options (optional): Configuration options for registration.
  • refresh(): Promise<void>: Refreshes the user's session using a redirect flow.
  • revoke(): Promise<void>: Revokes the current session tokens using a redirect flow.
  • logout(options?: LogoutOptions): Promise<void>: Logs out the user by redirecting to the logout page.
    • options (optional): Configuration options for logout.
  • handleCallback(url?: string): Promise<void>: Handles the callback after a redirect-based authentication or token exchange.
    • url (optional): The URL to handle for the callback.

Type: PopupContext Represents the available methods for Popup-based interactions.

  • login(options?: LoginOptions): Promise<void>: Initiates the login process using a popup window.
    • options (optional): Configuration options for login.
  • register(options?: RegisterOptions): Promise<void>: Registers a new user using a popup flow.
    • options (optional): Configuration options for registration.
  • refresh(): Promise<void>: Refreshes the user's session using a popup.
  • revoke(): Promise<void>: Revokes the current session tokens using a popup flow.
  • logout(options?: LogoutOptions): Promise<void>: Logs out the user using a popup window.
    • options (optional): Configuration options for logout.
  • handleCallback(url?: string): Promise<void>: Handles the callback after a popup-based authentication or token exchange.
    • url (optional): The URL to handle for the callback.

Links

Example app