Browse docs

@kolaylogin/javascript

Framework-free JS client. Subscribe to auth state, sign in with any method, hook up any UI library — no React, Vue, or Next.js required.

Copy this quickstart guide as a prompt for LLMs to implement KolayLogin in your application.

Install

npm install @kolaylogin/javascript

Create the client

import { createKolayLogin } from '@kolaylogin/javascript';

// baseUrl defaults to '/api/kl' — the same-origin proxy. Override only
// if you call api.kolaylogin.com directly from a same-eTLD+1 host or
// you call api.kolaylogin.com directly from a same-eTLD+1 host.
const kolay = createKolayLogin();

kolay.onAuthChange((auth) => {
  if (auth.isSignedIn) {
    document.body.dataset.user = auth.userId!;
  } else {
    document.location.href = '/sign-in';
  }
});

Sign-in flows

await kolay.signInEmailPassword('user@example.com', '…');
await kolay.signInMagicLink('user@example.com');
location.href = kolay.oauthRedirectUrl('google');

Attach to your own API

const token = kolay.getToken();
const res = await fetch('/api/private', {
  headers: { authorization: `Bearer ${token ?? ''}` },
});

Exports

  • createKolayLogin({ baseUrl })
  • state(), onAuthChange(fn), refresh()
  • signInEmailPassword(email, password), signUpEmailPassword(…)
  • signInMagicLink(email), oauthRedirectUrl(provider)
  • signOut(), getToken()

Works with Vite, webpack, Rollup, ESM CDNs (https://esm.sh/@kolaylogin/javascript), and bare <script type="module"> tags.