@anujyadav070/frontier-sdk
v1.0.11
Published
TypeScript SDK for Frontier authentication system
Readme
Frontier Auth SDK
A lightweight TypeScript SDK for authentication with your Frontier backend application. Currently supports tenant user registration and login functionality.
Installation
npm install @anujyadav070/frontier-sdkQuick Start
import FrontierAuth from '@anujyadav070/frontier-sdk';
const auth = new FrontierAuth();
auth
.setEndpoint('https://your-backend.com/api/v1')
.setProject('your-project-id')
.setKey('your-api-key');
// Sign up new tenant user
const user = await auth.account.create('username', '[email protected]', 'password');
// Login tenant user
const session = await auth.account.createEmailSession('[email protected]', 'password');Current Features
- ✅ Tenant user registration (Sign up)
- ✅ Tenant user email/password authentication (Login)
- ✅ Get current authenticated user information
- ✅ User logout functionality
- ✅ TypeScript support with full type definitions
- ✅ HTTP client with automatic error handling
- ✅ Configurable endpoint, project, and API key settings
- ✅ JWT token support for authenticated requests
- ✅ Custom exception handling (FrontierException, AuthException, etc.)
- ✅ Debug logging for development
API Reference
Client Configuration
const auth = new FrontierAuth();
// Set your backend endpoint (required)
auth.setEndpoint('https://your-backend.com/api/v1');
// Set project ID (required)
auth.setProject('your-project-id');
// Set API key (required for authentication)
auth.setKey('your-api-key');
// Set JWT token (optional, for authenticated requests)
auth.setJWT('your-jwt-token');Authentication Methods
Tenant User Registration
Create a new tenant user account:
const user = await auth.account.create(
'username', // Username (required)
'[email protected]', // Email address (required)
'securePassword' // Password (required)
);
console.log(user);
// Returns User object with: $id, $createdAt, $updatedAt, name, email, emailVerification, statusTenant User Login
Authenticate tenant user with email and password:
const session = await auth.account.createEmailSession(
'[email protected]', // Email address
'securePassword' // Password
);
console.log(session);
// Returns Session object with: $id, userId, expire, provider, ip, device info, etc.Get Current User
Get the currently authenticated user's information:
const currentUser = await auth.account.getCurrentUser();
console.log(currentUser);
// Returns User object with: $id, $createdAt, $updatedAt, name, email, emailVerification, statusLogout
Log out the current user session:
await auth.account.Logout();
// Logs out the current user and invalidates the sessionError Handling
The SDK includes comprehensive error handling with custom exception types:
import { FrontierException, AuthException, NetworkException, ValidationException } from '@anujyadav070/frontier-sdk';
try {
await auth.account.createEmailSession('[email protected]', 'wrong-password');
} catch (error) {
if (error instanceof AuthException) {
console.log('Authentication failed:', error.message);
console.log('Error code:', error.code);
console.log('Error type:', error.type);
} else if (error instanceof ValidationException) {
console.log('Validation error:', error.message);
} else if (error instanceof NetworkException) {
console.log('Network error:', error.message);
} else if (error instanceof FrontierException) {
console.log('Frontier error:', error.message);
} else {
console.log('Unknown error:', error.message);
}
}Exception Types
- FrontierException: Base exception class for all SDK errors
- AuthException: Authentication-related errors (401)
- NetworkException: Network connectivity issues
- ValidationException: Input validation errors (400)
Complete Example
import FrontierAuth from '@anujyadav070/frontier-sdk';
async function main() {
// Initialize SDK
const auth = new FrontierAuth();
// Configure (all required)
auth
.setEndpoint('https://your-backend.com/api/v1')
.setProject('your-project-id')
.setKey('your-api-key');
try {
// Sign up new tenant user
console.log('Creating tenant account...');
const user = await auth.account.create(
'johndoe',
'[email protected]',
'securePassword123'
);
console.log('Tenant user created:', user);
// Login tenant user
console.log('Logging in...');
const session = await auth.account.createEmailSession(
'[email protected]',
'securePassword123'
);
console.log('Login successful:', session);
// Get current user information
console.log('Getting current user...');
const currentUser = await auth.account.getCurrentUser();
console.log('Current user:', currentUser);
// Logout
console.log('Logging out...');
await auth.account.Logout();
console.log('Logout successful');
} catch (error) {
console.error('Error:', error.message);
}
}
main();API Endpoints
The SDK currently supports these Frontier backend endpoints:
POST /api/v1/tenantuser/tenantRegister- Tenant user registrationPOST /api/v1/tenantuser/tenatlogin- Tenant user loginGET /api/v1/tenantuser/getTenantSessions- Get current user informationDELETE /api/v1/tenantuser/tenantlogout/- Logout current user
Configuration Requirements
The SDK requires the following configuration before making API calls:
- Endpoint: Your Frontier backend URL (e.g.,
https://your-backend.com/api/v1) - Project ID: Your project identifier
- API Key: Your API key for authentication
Missing any of these will result in configuration errors.
Development
# Install dependencies
npm install
# Build the SDK
npm run build
# Watch for changes during development
npm run dev
# Prepare for publishing
npm run prepublishOnlyPackage Information
- Version: 1.0.10
- Package Name: @anujyadav070/frontier-sdk
- Repository: GitHub
- Author: ANUJ YADAV
- License: ISC
TypeScript Support
The SDK is built with TypeScript and includes full type definitions. All types are exported for use in your applications:
import { User, Session, FrontierException } from '@anujyadav070/frontier-sdk';Roadmap
Future versions will include:
- User profile management
- Password reset functionality
- Email verification
- Session management (list, delete sessions)
- JWT token creation and validation
- User preferences management
- Multi-factor authentication support
License
ISC
Contributing
This SDK is currently in active development. More authentication features will be added in future versions. Feel free to contribute by submitting issues or pull requests on GitHub.
