euroguard-auth
v1.0.13
Published
Easy authentication SDK for React applications - Euroguard Auth
Maintainers
Readme
@euroguard/auth
Easy authentication SDK for React applications. Works like Auth0 - Provider + Hook only.
Installation
npm install @euroguard/authQuick Start
1. Wrap your app with EuroguardProvider
import { EuroguardProvider } from '@euroguard/auth';
createRoot(document.getElementById('root')!).render(
<StrictMode>
<EuroguardProvider
domain={import.meta.env.VITE_EUROGUARD_DOMAIN}
clientId={import.meta.env.VITE_EUROGUARD_CLIENT_ID}
debug={true}
>
<App />
</EuroguardProvider>
</StrictMode>
);2. Use useAuth hook
import { useAuth } from '@euroguard/auth';
function App() {
const { user, status, login, logout, error, isLoading } = useAuth();
if (isLoading) return <div>Loading...</div>;
if (status === 'authenticated') {
return (
<div>
<h1>Welcome {user?.email}!</h1>
<button onClick={() => logout()}>Logout</button>
</div>
);
}
return (
<div>
{error && <p>Error: {error}</p>}
<button onClick={() => login('[email protected]')}>Login</button>
</div>
);
}API
EuroguardProvider
Props:
domain- API domain (default: 'https://get401.com')clientId- Client IDonSuccess- Callback on successful loginonError- Callback on errordebug- Enable debug logging
useAuth
Returns:
status- 'idle' | 'loading' | 'authenticated' | 'unauthenticated'user- Current user or nullnextStep- 'password' | 'otp' | nullerror- Error message or nullisLoading- Is loadinglogin(email)- Start login with emailchallenge(type, value)- Submit password or OTPlogout()- LogoutgetUser()- Get current userregister(email, password)- Register new userclearError()- Clear error message
License
MIT
