
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@cognite/react-auth
Advanced tools
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
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.
Install the package with yarn:
yarn add @cognite/react-auth
or npm
npm install @cognite/react-auth --save
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.
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
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
The SDK is written in native typescript, so no extra types needs to be defined.
How to release a new version:
$ npm version [patch/minor/major]
git push --tags)FAQs
Authenication helper for CDP including a React wrapper
The npm package @cognite/react-auth receives a total of 1 weekly downloads. As such, @cognite/react-auth popularity was classified as not popular.
We found that @cognite/react-auth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 50 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.