@getlocksmith/sdk
v1.2.4
Published
TypeScript/JavaScript client for the Locksmith public auth API
Readme
@getlocksmith/sdk
Official TypeScript / JavaScript client for the Locksmith public auth API. Works in Node 18+ (uses fetch). Includes optional adapters for Next.js middleware and tRPC context.
- Interactive API reference: getlocksmith.dev/docs/api
Install
npm install @getlocksmith/sdkOptional peers (only if you use the adapters):
npm install next @trpc/serverRequirements
- Node ≥ 18
- API key with prefix
lsm_live_(production) orlsm_sbx_(Sandbox). Environment is derived from the key — you never pass it separately.
Quick start
import { LocksmithClient } from '@getlocksmith/sdk'
const auth = new LocksmithClient({
apiKey: process.env.LOCKSMITH_API_KEY!,
// baseUrl optional; defaults to https://getlocksmith.dev
})
const { user, accessToken, refreshToken, expiresIn } = await auth.signIn({
email: '[email protected]',
password: 'secure-password',
})
const me = await auth.getUser(accessToken)Sign up, refresh, sign out
const session = await auth.signUp({ email: '…', password: '…' })
const next = await auth.refresh(session.refreshToken)
await auth.signOut(next.refreshToken)Magic link & password reset
await auth.sendMagicLink('[email protected]')
const verified = await auth.verifyMagicLink({ token, projectId: '…' })
await auth.sendPasswordReset('[email protected]')
await auth.updatePassword({ token: resetToken, newPassword: '…' })OAuth (social sign-in)
const { authorizationUrl } = await auth.initiateOAuth({ provider: 'github /* or google, etc. */' })
// Redirect the user’s browser to authorizationUrl, then on your backend:
const tokens = await auth.exchangeOAuthCode(code)Hosted SSO (OIDC grant bridge, Pro)
const { redirectUrl } = await auth.completeOidcGrant({
requestToken,
approved: true,
userId,
scopes: ['openid', 'profile', 'email'],
})Verify access token locally (RS256)
Fetch your project’s public PEM from the dashboard, then:
const payload = auth.verifyToken(accessToken, publicKeyPem)Adapters
- Next.js:
import { createMiddleware } from '@getlocksmith/sdk/adapters/next' - tRPC:
import { createTRPCContext } from '@getlocksmith/sdk/adapters/trpc'
License
MIT
