hasura-auth-js
v3.0.0
Published
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.
Maintainers
Readme
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-jspackage 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.
Versioning
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.
Features
- 🔐 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.
Installation
npm install hasura-auth-js
# or
pnpm add hasura-auth-js
# or
yarn add hasura-auth-jsQuick Start
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: '[email protected]',
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: '[email protected]',
password: 'secure-password'
})
// Check authentication status
const isAuthenticated = auth.isAuthenticated()
const currentSession = auth.getSession()
// Sign out
await auth.signOut()More Examples
// Passwordless email (magic link)
await auth.signIn({ email: '[email protected]' })
// 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.
Migration from @nhost/hasura-auth-js
This package is a drop-in replacement for the deprecated @nhost/hasura-auth-js:
Uninstall the old package:
npm uninstall @nhost/hasura-auth-jsInstall the new package:
npm install hasura-auth-jsUpdate your imports:
// 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.
Documentation
- FEATURES.md: Complete feature list and API methods
- OPTIMIZATION_NOTES.md: Technical details and optimization notes
- Original Nhost Documentation: Detailed API reference
Requirements
- Node.js: >= 18.0.0
- Browsers: Modern browsers with ES2022 support
- Hasura Auth: Compatible with Hasura Auth v0.38.0+
Credits
This package is based on the original work by Nhost:
- Original package:
@nhost/hasura-auth-js - Original repository: nhost/nhost
- Original documentation: Nhost Documentation
License
MIT
