Registry / aws / amplify-auth-hooks

amplify-auth-hooks

JSON →
library1.0.0jsnpmunverified

React hooks for AWS Amplify authentication. Version 1.0.0 provides a set of hooks like useAuth, useSignIn, useSignUp, etc., wrapping Amplify Auth operations. Released as a single version with no updates since. Differentiates by offering hook-based API for Amplify Auth, tightly coupled with React lifecycle. Requires @aws-amplify/auth, @aws-amplify/core, amazon-cognito-identity-js, and react as peer dependencies. Ships TypeScript types.

npm install amplify-auth-hooks
INSTALL
IMPORT
SIG · AMPLIFY-AUTH-HOOKS
A
amplify-auth-hooks
awsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useAuth
import { useAuth } from 'amplify-auth-hooks'
import useAuth from 'amplify-auth-hooks'
Named export, not default.
useSignIn
import { useSignIn } from 'amplify-auth-hooks'
const { useSignIn } = require('amplify-auth-hooks')
CommonJS require works, but prefer ESM.
useSignUp
import { useSignUp } from 'amplify-auth-hooks'
import { SignUp } from 'amplify-auth-hooks'
Hook name is useSignUp, not SignUp.

Shows basic usage of useAuth hook to get authentication state.

import React from 'react'; import { useAuth } from 'amplify-auth-hooks'; function AuthStatus() { const { user, loading, error } = useAuth(); if (loading) return <div>Loading...</div>; if (error) return <div>Error: {error.message}</div>; if (user) return <div>Welcome, {user.username}</div>; return <div>Not logged in</div>; } export default AuthStatus;
Debug
Known issues
gotchaForgot to configure Amplify before using hooks
fix
Call Amplify.configure() once at app root.
affects: *
gotchaUndefined user on first render
fix
Use loading state to handle asynchronous auth check.
affects: *
deprecatedOld version only supports class components?
fix
Upgrade to latest version for hooks support.
affects: <=1.0.0
Errors
Common errors & fixes
Cannot read property 'amplify' of undefined
Amplify not configured or imported
fix
import Amplify from '@aws-amplify/core'; Amplify.configure(awsConfig);
TypeError: (0 , _auth.useAuth) is not a function
Wrong import (default vs named)
fix
import { useAuth } from 'amplify-auth-hooks';
Uncaught ReferenceError: require is not defined
Using CommonJS require in browser bundle
fix
Use ES module import syntax.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@aws-amplify/authrequiredCore dependency for Auth API
@aws-amplify/corerequiredRequired for configuration
amazon-cognito-identity-jsrequiredUnderlying Cognito library
reactrequiredPeer dependency for hooks
Agent activity
45 hits · last 30 days
node
42
Resources
amplify-auth-hooks — npm install amplify-auth-hooks · libregistry