@kothatech/auth-js
A framework-agnostic client SDK for managing the complex PKCE authorization code flow natively in the browser.
Installation
npm install @kothatech/auth-jsUsage
Initiate login from your SPA:
import KothaAuth from '@kothatech/auth-js';
const auth = new KothaAuth({
clientId: 'YOUR_CLIENT_ID',
redirectUri: window.location.origin + '/callback',
issuer: 'https://auth.kotha.im' // Or http://localhost:4000
});
// Redirects user to Kotha Auth login page
document.getElementById('login').onclick = () => auth.loginWithRedirect();Handle the callback route (e.g. `/callback`):
// Automatically exchanges the code for a JWT token
try {
const token = await auth.handleRedirectCallback();
console.log('Logged in successfully', token);
} catch (err) {
console.error('Login failed', err);
}