
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
react-cognito-auth-hook
Advanced tools
Package for handling and managing user authentication in react applications
A React hook for handling AWS Cognito authentication flows with built-in token management and persistence.
npm install react-cognito-auth-hook
or
yarn add react-cognito-auth-hook
Before using this package, you need:
USER_PASSWORD_AUTH
, USER_AUTH
authentication flowsYou will need the following information from your AWS Cognito setup:
First, create a configuration object with your AWS Cognito details:
const config = {
region: "YOUR_AWS_REGION",
userPoolId: "YOUR_USER_POOL_ID",
clientId: "YOUR_CLIENT_ID",
};
import { useCognitoAuth } from 'react-cognito-auth-hook';
function App() {
const {
authData,
authState,
login,
initSignUp,
confirmSignUp,
signOut
} = useCognitoAuth({ config });
// Check authentication state
if (authState === 'AUTHENTICATED') {
return (
<div>
<h1>Welcome, {authData?.username}!</h1>
<button onClick={signOut}>Sign Out</button>
</div>
);
}
return (
<div>
<h1>Please log in</h1>
{/* Your login/signup forms here */}
</div>
);
}
try {
await login(username, password);
// User is now logged in
} catch (error) {
// Handle login error
}
try {
// Initialize sign up
await initSignUp(username, password, passwordConfirm);
// Confirm sign up with code
await confirmSignUp(username, confirmationCode);
// User is now signed up and logged in
} catch (error) {
// Handle signup error
}
try {
await changePassword(currentPassword, newPassword, newPasswordConfirm);
// Password successfully changed
} catch (error) {
// Handle password change error
}
try {
await resendConfirmationCode(username);
// Confirmation code sent
} catch (error) {
// Handle error
}
The hook provides the following authentication states:
INIT
: Initial loading stateAUTHENTICATED
: User is authenticatedUNAUTHENTICATED
: User is not authenticatedauthData
: Object containing the current authentication data (tokens, username)authState
: Current authentication statelogin(username: string, password: string)
: Login with username and passwordinitSignUp(username: string, password: string, passwordConfirm: string)
: Start the signup processconfirmSignUp(username: string, code: string, callback?: Function)
: Confirm signup with verification coderesendConfirmationCode(username: string)
: Resend verification codesignOut()
: Sign out the current userchangePassword(prevPassword: string, newPassword: string, newPasswordConfirm: string)
: Change user's passwordThis package handles authentication tokens securely by:
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
Package for handling and managing user authentication in react applications
The npm package react-cognito-auth-hook receives a total of 0 weekly downloads. As such, react-cognito-auth-hook popularity was classified as not popular.
We found that react-cognito-auth-hook demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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 now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.