
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@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 8 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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.