
Security News
US Government Forces Anthropic to Pull Claude Fable Days After Launch
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.
cognito-token-observer
Advanced tools
Monitors date expiration of access and id tokens provided by Amazon Cognito. Refreshes when expired.
Authorize users with Amazon Cognito and use result token in 3rd party projects outside AWS.
projects:
npm install cognito-token-observer
or
yarn add cognito-token-observer
Add CognitoAuthObserver to your component:
import React, { useEffect, useState } from 'react'
import ReactDOM from 'react-dom/client'
import { CognitoAuthObserver } from 'cognito-token-observer'
function App() {
const [userData, setUserData] = useState([])
const cognitoObserver = CognitoAuthObserver({ // init
clientId: process.env.REACT_APP_COGNITO_CLIENT_ID,
poolDomain: process.env.REACT_APP_COGNITO_POOL_DOMAIN,
redirectUrl: process.env.REACT_APP_COGNITO_REDIRECT_URI,
region: process.env.REACT_APP_COGNITO_REGION,
userPoolId: process.env.REACT_APP_COGNITO_USER_POOL_ID,
});
cognitoObserver.onTokenUpdate(() => { // callback on token update
setUserData(cognitoObserver.getUserData())
}, 'onTokenUpdateKey')
const getCodeFromBrowser = () => {
// get code after signin/up to aws cognito
// then pass to cognitoObserver
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
const code = params['code'];
}
const cognitoCode = getCodeFromBrowser()
useEffect(() => {
cognitoObserver.init(cognitoCode)
.then(isAuthenticated => {
console.log('Token updated:', isAuthenticated)
})
}, [])
return (
<div>
{JSON.stringify(userData)}
</div>
)
}
In the root package
npm run build
npm pack
# will create .tgz file cognito-token-observer-{x.x.x}.tgz
add path in example
cd example
Open package.json
change dependency from
"cognito-token-observer": "^x.x.x",
to the path
# in my case version 2.2.2.
"file:../cognito-token-observer-2.2.2.tgz"
FAQs
Monitor and refresh AWS Cognito tokens for the current session
We found that cognito-token-observer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.