Hasura Auth client library for JavaScript/TypeScript. A drop-in replacement for the deprecated @nhost/hasura-auth-js package. Supports Email/Password, OAuth, WebAuthn, Passwordless, MFA, and more.
npm install hasura-auth-js


Optimized Hasura Auth client library with latest packages and improved performance. A drop-in replacement for the deprecated @nhost/hasura-auth-js package.
> Note: This package is based on the original @nhost/hasura-auth-js package by Nhost. The original package has been deprecated in favor of @nhost/nhost-js@^4.0.0. This fork provides an updated version with the latest dependencies and optimizations.
This package uses version 3.0.0 to indicate it's the next major version after the deprecated @nhost/hasura-auth-js package (which ended at v2.12.0). The major version bump reflects:
- Major dependency updates: WebAuthn v13.2.2, Vite 7, TypeScript 5.9
- API changes: Updated WebAuthn function signatures
- Removed deprecated packages: No longer depends on deprecated @simplewebauthn/types
- Modern build tooling: Latest stable versions of all dependencies
This follows semantic versioning principles, where version 3.0.0 signals significant updates and improvements over the 2.x series.
- π Multiple Authentication Methods: Email/Password, Passwordless, OAuth, WebAuthn, Anonymous, MFA
- π Automatic Token Refresh: Built-in token refresh with Bearer token support
- π MFA Support: Multi-Factor Authentication with TOTP
- π« Personal Access Tokens: Create and manage PATs
- π± Cross-tab Synchronization: Automatic session sync across browser tabs
- π― TypeScript Support: Full TypeScript definitions included
- β‘ Optimized: Latest stable dependencies and modern build tools
- π¦ Dual Format: Supports both ESM and CommonJS
- πΊοΈ Source Maps: Full source maps for debugging
For a complete list of features and methods, see FEATURES.md.
``bash`
npm install hasura-auth-jsor
pnpm add hasura-auth-jsor
yarn add hasura-auth-js
`typescript
import { HasuraAuthClient } from 'hasura-auth-js'
// Initialize the client
const auth = new HasuraAuthClient({
url: 'https://your-hasura-auth-endpoint.com'
})
// Sign up
const { session, error } = await auth.signUp({
email: 'user@example.com',
password: 'secure-password'
})
if (error) {
console.error('Sign up error:', error)
} else {
console.log('User signed up:', session?.user)
}
// Sign in
const { session: signInSession, error: signInError } = await auth.signIn({
email: 'user@example.com',
password: 'secure-password'
})
// Check authentication status
const isAuthenticated = auth.isAuthenticated()
const currentSession = auth.getSession()
// Sign out
await auth.signOut()
`
`typescript
// Passwordless email (magic link)
await auth.signIn({ email: 'user@example.com' })
// OAuth provider
await auth.signIn({ provider: 'google' })
// Anonymous sign in
await auth.signIn()
// Get access token
const token = auth.getAccessToken()
// Listen to auth state changes
auth.onAuthStateChanged((event, session) => {
console.log('Auth state changed:', event, session)
})
`
For more examples and API reference, see FEATURES.md.
This package is a drop-in replacement for the deprecated @nhost/hasura-auth-js:
1. Uninstall the old package:
`bash`
npm uninstall @nhost/hasura-auth-js
2. Install the new package:
`bash`
npm install hasura-auth-js
3. Update your imports:
`typescript`
// Before
import { HasuraAuthClient } from '@nhost/hasura-auth-js'
// After
import { HasuraAuthClient } from 'hasura-auth-js'
That's it! The API is identical, so no other code changes are needed.
- FEATURES.md: Complete feature list and API methods
- OPTIMIZATION_NOTES.md: Technical details and optimization notes
- Original Nhost Documentation: Detailed API reference
- Node.js: >= 18.0.0
- Browsers: Modern browsers with ES2022 support
- Hasura Auth: Compatible with Hasura Auth v0.38.0+
This package is based on the original work by Nhost:
- Original package: @nhost/hasura-auth-js`
- Original repository: nhost/nhost
- Original documentation: Nhost Documentation
MIT