Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@crydensync/sdk

JavaScript/TypeScript SDK for CrydenSync's HTTP API. Works in browsers and Node — thin fetch wrapper, no dependencies.

Install

npm install @crydensync/sdk

Usage

import { Cryden, CrydenError } from "@crydensync/sdk";

const cryden = new Cryden({ baseUrl: "https://auth.yourapp.com" });

await cryden.signUp("devray@example.com", "SecurePass123!");
await cryden.login("devray@example.com", "SecurePass123!");

// Auto-refreshes on an expired access token and retries once —
// you never manually manage token refresh.
const sessions = await cryden.listSessions();

try {
  await cryden.login(email, password);
} catch (err) {
  if (err instanceof CrydenError) {
    switch (err.code) {
      case "invalid_credentials": /* ... */ break;
      case "account_locked": /* ... */ break;
      case "rate_limited": /* ... */ break;
    }
  }
}

Token storage

Defaults to localStorage in a browser, an in-memory Map elsewhere (Node, SSR). Pass your own adapter for anything else (React Native, sessionStorage, encrypted storage):

const cryden = new Cryden({
  baseUrl: "...",
  storage: myCustomAdapter, // implements StorageAdapter: get/set/remove
});

Behavior worth knowing

  • changePassword clears locally stored tokens after success — the engine just revoked every session including the current one, so this matches real behavior, not an SDK choice.
  • confirmEmailChange requires no authentication — matches the API, since the user may click the link from an email client with no active session.
  • A failed silent refresh (expired or reused refresh token) clears stored tokens automatically. Catch the resulting error and redirect to login — the SDK doesn't retry beyond one refresh attempt.

Development

npm install
npm run build          # tsup for ESM/CJS bundles + tsc for type declarations
node smoketest/main.mjs http://localhost:8080   # run against a live api instance

License

MIT

About

Official JavaScript SDK for CrydenSync authentication.

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages