@anujyadav070/frontier-sdk
v1.0.7
Published
TypeScript SDK for Frontier authentication system
Readme
Frontier Auth SDK
A lightweight TypeScript SDK for authentication with your Frontier backend application. Currently supports 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/v1')
.setProject('your-project-id');
// Sign up new user
const user = await auth.account.create('unique-id', '[email protected]', 'password', 'John Doe');
// Login user
const session = await auth.account.createEmailSession('[email protected]', 'password');Current Features
- ✅ User registration (Sign up)
- ✅ Email/password authentication (Login)
- ✅ TypeScript support
- ✅ HTTP client with automatic error handling
- ✅ Configurable endpoint and project settings
API Reference
Client Configuration
const auth = new FrontierAuth();
// Set your backend endpoint
auth.setEndpoint('https://your-backend.com/v1');
// Set project ID
auth.setProject('your-project-id');
// Set API key (for server-side usage)
auth.setKey('your-api-key');
// Set JWT token (for authenticated requests)
auth.setJWT('your-jwt-token');Authentication Methods
Sign Up
Create a new user account:
const user = await auth.account.create(
'unique-user-id', // User ID (must be unique)
'[email protected]', // Email address
'securePassword', // Password
'John Doe' // Name (optional)
);
console.log(user);
// Returns User object with: $id, $createdAt, $updatedAt, name, email, emailVerification, statusLogin
Authenticate 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.Error Handling
import { FrontierException, AuthException } from 'frontier-auth-sdk';
try {
await auth.account.createEmailSession('[email protected]', 'wrong-password');
} catch (error) {
if (error instanceof AuthException) {
console.log('Authentication failed:', error.message);
} else {
console.log('Error:', error.message);
}
}Complete Example
import FrontierAuth from 'frontier-auth-sdk';
async function main() {
// Initialize SDK
const auth = new FrontierAuth();
// Configure
auth
.setEndpoint('https://your-backend.com/v1')
.setProject('your-project-id');
try {
// Sign up new user
console.log('Creating account...');
const user = await auth.account.create(
'user-123',
'[email protected]',
'securePassword123',
'John Doe'
);
console.log('User created:', user);
// Login user
console.log('Logging in...');
const session = await auth.account.createEmailSession(
'[email protected]',
'securePassword123'
);
console.log('Login successful:', session);
} catch (error) {
console.error('Error:', error.message);
}
}
Development
# Install dependencies
npm install
# Build the SDK
npm run build
# Watch for changes during development
npm run devLicense
ISC
Contributing
This SDK is currently in development. More authentication features will be added in future versions.
