About OnlyJah
The OnlyJah SDK
@onlyjah/sdk
One package for every OnlyJah site and app. It lives in onlyjah/soil at clients/sdk. A site copies it into vendor/onlyjah-sdk and records the commit in vendor/onlyjah-sdk.lock.json.
"dependencies": { "@onlyjah/sdk": "file:vendor/onlyjah-sdk" }| Import | For |
|---|---|
@onlyjah/sdk/session | OnlyJah sites that pass /api/auth through: the session, tokens, pods |
@onlyjah/sdk/session/react | The same, as React hooks and the account panel |
@onlyjah/sdk/signin | Sign in with OnlyJah for any server or app (OAuth 2.1 + PKCE) |
@onlyjah/sdk/better-auth | onlyJahProvider() for sites on Better Auth |
@onlyjah/sdk · /react · /style.css | A site’s shop, blog, cart and checkout |
The session
Pass sign-in through your own /api/auth to Soil (onlyjah.com does it in scripts/auth-proxy.mjs) so the session cookie is your site’s own.
import { createSoilAuth } from '@onlyjah/sdk/session'
export const auth = createSoilAuth({ appId: 'my-site', authUrl: '/api/auth' })
const session = await auth.session() // { user } or null
const token = await auth.token() // for api.onlyjah.com, kept fresh
const { human, contexts, active } = await auth.contexts()
await auth.actAs(podId) // act as a pod; actAs(null) for yourselfawait auth.sendSignInCode(email) // a six-digit code by email
await auth.signInWithCode({ email, otp }) // signs in, or joins
// With two-step on, a password sign-in needs the authenticator code
// (/api/auth/two-factor/verify-totp) before the session exists.Sign in with OnlyJah
For a site or app outside OnlyJah. Ask an operator to register it; phone and browser-only apps are public clients (PKCE, no secret).
import { createOnlyJah } from '@onlyjah/sdk/signin'
const oj = createOnlyJah({ soilUrl: 'https://soil.onlyjah.com', clientId, clientSecret, redirectUri })
const { url, pending } = await oj.signInUrl() // send the person to url; keep pending
const { tokens, claims } = await oj.handleCallback(callbackUrl, pending)
const me = await oj.userinfo(tokens.accessToken)Shop and blog
Read with the site’s public key, right from the page. Or paste the embed once.
import { createOnlyJah } from '@onlyjah/sdk'
const site = createOnlyJah({ key: 'ojpk_…' })
const { products } = await site.products({ q: 'cd' })
const { posts } = await site.posts()<script type="module" src="https://api.onlyjah.com/embed/v1.js"></script>
<onlyjah-shop site-key="ojpk_…"></onlyjah-shop>
<onlyjah-blog site-key="ojpk_…"></onlyjah-blog>Market and members
On test only for now. The market is Soil, so it uses the session: same-origin calls to your /api/auth.
const get = (p) => fetch('/api/auth' + p, { credentials: 'include' }).then((r) => r.json())
const { listings } = await get('/market/listings?terms=barter')
const { members } = await get('/members?q=jah')Every call is listed at onlyjah.com/api.