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

@emdgroup/react-auth

v1.7.0

Published

React hooks implementing the Authorization Code Grant Flow with PKCE.

Downloads

99

Readme

Interfaces

Functions

UserContextProvider

UserContextProvider(__namedParameters): JSX.Element

This library implements the Authorization Code Grant Flow with PKCE.

import { UserContextProvider } from '@emdgroup/react-auth';
function App(): JSX.Element {
  return (
    <UserContextProvider autoLogin clientId="...">
      <Content />
    </UserContextProvider>
  );
}

function Content(): JSX.Element {
  const { info } = useUser();
  return <p>{info.email}</p>;
}

Parameters

| Name | Type | | :------ | :------ | | __namedParameters | ProviderOptions |

Returns

JSX.Element


useUser

useUser(): UserContext

Returns the user context previously established with UserContextProvider.

const { info, session, login, logout, authHeader } = useUser();

useEffect(() => {
  if (!session) return; // user is not logged in
  fetch('/api/pet', { headers: authHeader }).then(...);
}, [session, authHeader]);

Returns

UserContext

UserContext

The user context object is returned by the useUser hook.

Properties

authHeader

Optional authHeader: Object

Convenience header object containing the Authorization header value set to the access token.

Index signature

▪ [key: string]: string


info

Optional info: UserInfo

Provides the UserInfo object if the user is authenticated.


login

Optional login: (opts?: LoginOptions) => void

Type declaration

▸ (opts?): void

Function to initiate the login flow.

Parameters

| Name | Type | | :------ | :------ | | opts? | LoginOptions |

Returns

void


loginUrl

Optional loginUrl: string

Set to the URL that the user is redirected to initiate the authorization flow. Useful when you need to start the login flow in a separate window or tab. Use in combination with login({ refresh: false }).


logout

Optional logout: () => void

Type declaration

▸ (): void

Function to log the user out.

Returns

void


session

Optional session: UserSession

Provides the UserSession object if the user is authenticated.

ProviderOptions

Properties

acrValues

Optional acrValues: string

Request a type of multi-factor authentication. Currently, mfa is the only supported value.


additionalParameters

Optional additionalParameters: string

Additional query parameters, such as state=xyz.


autoLogin

Optional autoLogin: boolean

When enabled, the user will automatically be logged in when the page is loaded. Defaults to false.


clientId

clientId: string

Client ID as provided by the IdP.


domainHint

Optional domainHint: string

Domain name to directly forward a user to the login page for a certain auth domain.


idpHost

Optional idpHost: string

Overwrite the IdP host, defaults to login.emddigital.com.


prompt

Optional prompt: "login"

Whether the authorization server prompts the user for re-authentication.


redirectUri

Optional redirectUri: string

Overwrite the redirect URI, defaults to the current hostname + /auth.


refreshSession

Optional refreshSession: boolean

Persist and use the refreshToken to renew an expired accessToken. Defaults to false.


userInfoEndpoint

Optional userInfoEndpoint: string

Overwrite the userinfo endpoint, defaults to /oauth2/userinfo.

LoginOptions

Object representing the options for the login function of the UserContext.

Properties

entrypoint

Optional entrypoint: string

Entrypoint to redirect the user to after successful authentication. Defaults to the URL that the user initially visited.


redirect

Optional redirect: boolean

Automatically redirect the user to the login URL and to the entrypoint after successful authentication. Disabling this will disable all redirects. Defaults to false.

UserSession

Object containing the OIDC tokens and expiration time.

Properties

accessToken

accessToken: string

OAuth access token provided by the IDP


expires

expires: number

Epoch time in seconds when the access token expires


idToken

Optional idToken: string

OAuth ID token provided by the IDP


refreshToken

Optional refreshToken: string

OAuth refresh token provided by the IDP

UserInfo

Object representing the user details as provided by the IdP userInfo endpoint.

Hierarchy

  • Record<string, unknown>

    UserInfo

Properties

email

email: string

Email address


familyName

Optional familyName: string

Family name of provided


givenName

Optional givenName: string

Given name of provided


sub

sub: string

Subject identifier