@tavallaie/allauth-api-client
v2.0.1
Published
Axios client for django‑allauth headless API
Maintainers
Readme
@tavallaie/allauth‑api‑client
Axios client library for consuming the django‑allauth headless API in browser contexts.
Installation
npm install @tavallaie/allauth‑api‑client Environment Variables
The client reads two environment variables at runtime:
NEXT_PUBLIC_API_URLThe base URL of your Django backend (e.g. https://api.example.com)
NEXT_PUBLIC_AUTH_BASE_PATHThe headless AllAuth path prefix (default: /_allauth/browser/v1)
Override to match custom deployments.
Place these in your .env or hosting configuration:
NEXT_PUBLIC_API_URL=https://api.example.com
NEXT_PUBLIC_AUTH_BASE_PATH=/allauth/browser/v1 Usage
import { allauthApi } from "@tavallaie/allauth-api-client";
// Login with email + password
const loginResponse = await allauthApi.login({
email: "[email protected]",
password: "SuperSecret123",
});
// List active sessions
const sessions = await allauthApi.listSessions();
// Revoke a session
await allauthApi.revokeSessions([sessions[0].id]);API Methods
The allauthApi object exposes methods matching each headless endpoint:
Configuration & Status
getConfig()getSessionStatus()
Login / Logout
login({ username?, email?, phone?, password })logout()
Signup & Verification
signup({ username, email, password })getEmailVerification(key)verifyEmail(key)resendEmailVerification()verifyPhone(code)resendPhoneVerification()
Password Reset & Reauthentication
requestPasswordReset(email)getPasswordResetInfo(key)resetPassword(key, newPassword)reauthenticate(password)
Social Providers
providerRedirect({ provider, callback_url, process })providerTokenLogin({ provider, token, process })providerSignupInfo()providerSignup({ email, username })
Two‑Factor Authentication
listAuthenticators()getTOTP()activateTOTP(code)deactivateTOTP()listRecoveryCodes()regenerateRecoveryCodes()
Session Tracking
listSessions()revokeSessions(sessionIds)
Account Settings
getEmails()/addEmail(email)/resendEmail(email)/changePrimaryEmail(email)/removeEmail(email)changePassword(currentPassword, newPassword)getPhone()/changePhone(phone)listProviders()/disconnectProvider({ provider, account })
Error Handling
Each method returns a Promise that resolves to the parsed JSON response.
HTTP errors (4xx/5xx) will reject; catch and inspect error.response.data for details.
try {
await allauthApi.login({ email, password });
} catch (err) {
console.error("Login failed:", err.response?.data || err.message);
}Contributing
- Fork the repo
- Create your feature branch (git checkout -b feature/XYZ)
- Commit your changes (git commit -m "Add XYZ")
- Push to the branch (git push origin feature/XYZ)
- Open a Pull Request
License
MIT © Ali Tavallaie
