React SDK for Erikey - B2B authentication and user management. UI components based on better-auth-ui.
npm install @erikey/reactReact SDK for Auth.ai - Easy authentication integration for your React applications.
``bash`
npm install @auth-ai/sdkor
pnpm add @auth-ai/sdkor
yarn add @auth-ai/sdk
`tsx
import { AuthProvider } from '@auth-ai/sdk';
function App() {
return (
);
}
`
`tsx
import { useAuth, ProtectedRoute } from '@auth-ai/sdk';
function Dashboard() {
const { user, signOut } = useAuth();
return (
Welcome, {user?.email}!
);
}
`
Wrap your application with this provider to enable authentication.
`tsx`
baseURL: 'https://api.yourapp.com',
credentials: 'include', // optional
}}
>
{children}
Access authentication state and methods.
`tsx`
const {
user, // Current user object
session, // Current session
isLoading, // Loading state
isAuthenticated, // Boolean auth status
signIn, // Sign in function
signUp, // Sign up function
signOut, // Sign out function
refreshSession, // Manually refresh session
} = useAuth();
Get current user data.
`tsx
const user = useUser();
if (user) {
console.log(user.email, user.role);
}
`
Access organization data and methods.
`tsx`
const {
organization, // Current active organization
organizations, // List of user's organizations
switchOrganization, // Switch to different org
isLoading,
} = useOrganization();
Protect routes that require authentication.
`tsx`
redirectTo="/login" // Optional: redirect URL
>
`tsx
import { useAuth } from '@auth-ai/sdk';
import { useState } from 'react';
function LoginForm() {
const { signIn } = useAuth();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
try {
await signIn(email, password);
} catch (error) {
console.error('Login failed:', error);
}
};
return (
$3
`tsx
import { useUser } from '@auth-ai/sdk';function UserProfile() {
const user = useUser();
if (!user) {
return
Not logged in;
} return (
{user.name || user.email}
Role: {user.role}
Joined: {new Date(user.createdAt).toLocaleDateString()}
);
}
``MIT