JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q86251F
  • License MIT

Official Stackure authentication SDK for JavaScript and TypeScript

Package Exports

  • stackure

Readme

Stackure JavaScript SDK

CI npm version npm downloads Node.js version npm provenance License: MIT

Authentication for your app. One line.

Install

npm install stackure

Requires Node.js 18+.

Protect a route

import { auth } from 'stackure';

app.get('/admin', auth({ appId: 'my-app-id', roles: ['admin'] }), (req, res) => {
  res.json({ user: req.user });
});
  • API requests get JSON errors
  • Browser requests get redirected to sign-in

Verify manually

import { verify } from 'stackure';

const result = await verify({ appId: 'my-app-id', request: req });

if (!result.authenticated) {
  return res.status(result.error.code).json({ error: result.error.message });
}

res.json({ user: result.user });

Client functions

import { sendMagicLink, validateSession, signIn, logout } from 'stackure';

await sendMagicLink({ email: 'user@example.com', appId: 'my-app-id' });
await signIn('my-app-id');

const session = await validateSession('my-app-id');
// session.authenticated, session.user, session.sign_in_url

await logout();

Custom client

import { StackureClient } from 'stackure';

const client = new StackureClient({
  baseUrl: 'https://staging.stackure.com',
  timeout: 5000,
});

Errors

ValidationError | NetworkError | AuthenticationError | ForbiddenError | TimeoutError

import {
  ValidationError,
  NetworkError,
  AuthenticationError,
  ForbiddenError,
  TimeoutError,
} from 'stackure';

Contributing

See CONTRIBUTING.md. Commit messages must follow Conventional Commits — release-please depends on this.

Security

See SECURITY.md. Releases are published with npm provenance (Sigstore-backed SLSA L3).

License

MIT