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

@cognite/react-auth

v2.2.4

Published

Authenication helper for CDP including a React wrapper

Downloads

13

Readme

DEPRECATED - only to be used with Javascript SDK 1.x.x. For javascript SDK 2.x.x please see this guide in how to authenticate the client: https://github.com/cognitedata/cognitesdk-js/blob/v1/guides/authentication.md

Cognite React Auth

Build Status

The Cognite React Auth makes it easy to integrate Cognite's login flow into any React applications.

You need to use the Cognite JavaScript SDK with this module.

Installation

Install the package with yarn:

yarn add @cognite/react-auth

or npm

npm install @cognite/react-auth --save

Getting Started

Import ReactAuthProvider:

import { ReactAuthProvider } from '@cognite/react-auth';

Wrap your application with ReactAuthProvider:

<ReactAuthProvider
  project={PROJECT_NAME}
  redirectUrl={window.location.href}
  errorRedirectUrl={window.location.href}
>
  <AuthenticatedComponent />
</ReactAuthProvider>

To persist authorization token in the local storage add enableTokenCaching prop:

<ReactAuthProvider
  project={PROJECT_NAME}
  enableTokenCaching
  ...

If your app uses a routing library, you can provide routes for successful authorization in redirectUrl prop and for failed in errorRedirectUrl prop:

<ReactAuthProvider
  project={PROJECT_NAME}
  redirectUrl="/authenticated_route"
  errorRedirectUrl="/login_error_route"
  ...

See the example on how to use this module.

Popup Login

If you need to preserve the state of your react app during authorization, you can use "popup" login that opens a new tab in the browser. To do that add usePopup prop:

<ReactAuthProvider
  project={PROJECT_NAME}
  redirectUrl={window.location.href}
  errorRedirectUrl={window.location.href}
  usePopup
>
  <AuthenticatedComponent />
</ReactAuthProvider>

NOTE: With "popup" login it's very important to use ReactAuthProvider on the top level of your application without any condition, even though the project is undefined or empty, ReactAuthProvider should be rendered. It's necessary in order the app that runs in the popup window after authorization will render ReactAuthProvider component and the component will close the popup window. See the example

Login Renderer

There is an optional prop loginRenderer that can be used as fallback render in case of project prop is either undefined or empty:

<ReactAuthProvider
  project={PROJECT_NAME}
  redirectUrl={window.location.href}
  errorRedirectUrl={window.location.href}
  usePopup
  loginRenderer={<ProjectSelector onProjectSelected={this.onProjectSelected} />}
>
  <AuthenticatedComponent />
</ReactAuthProvider>

See the example

Using Typescript

The SDK is written in native typescript, so no extra types needs to be defined.

Documentation

License

Apache 2.0

Release

How to release a new version:

  1. Create a new branch
  2. Commit changes (if any)
  3. Run
    $ npm version [patch/minor/major]
  4. Push branch and push tags (git push --tags)
  5. Create a new pull requests
  6. A new version will be published when PR is merged