@productcraft/auth 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ The SDK splits into three caller contexts.
|
|
|
21
21
|
|
|
22
22
|
### 1. Workspace-wide admin
|
|
23
23
|
|
|
24
|
-
```ts
|
|
24
|
+
```ts before
|
|
25
25
|
// /v1/apps, /v1/stats/me
|
|
26
26
|
const apps = await auth.apps.list();
|
|
27
27
|
|
|
@@ -39,7 +39,7 @@ const stats = await auth.stats.get();
|
|
|
39
39
|
|
|
40
40
|
Pre-binds the appId path param so resource methods read like `app.endUsers.list()`.
|
|
41
41
|
|
|
42
|
-
```ts
|
|
42
|
+
```ts before
|
|
43
43
|
const app = auth.app("<app-uuid>");
|
|
44
44
|
|
|
45
45
|
// EndUsers — profile updates only carry { display_name?, email? }.
|
|
@@ -71,7 +71,7 @@ await app.authConfig.update({ passwordMinLength: 12 });
|
|
|
71
71
|
|
|
72
72
|
For backend route handlers mediating auth between your SPA and Auth. Pre-binds the appSlug.
|
|
73
73
|
|
|
74
|
-
```ts
|
|
74
|
+
```ts before
|
|
75
75
|
const consumer = auth.consumer("my-app-slug");
|
|
76
76
|
|
|
77
77
|
// Sign-in
|
|
@@ -143,7 +143,7 @@ Both `request*` and `send*` return `{}` when the contact doesn't match (or is al
|
|
|
143
143
|
|
|
144
144
|
`consumer.auth.signinWithProvider` lets a BFF exchange a provider-issued identity token for an Auth `{ access_token, refresh_token }` pair. The endpoint creates the EndUser on first sign-in and returns the same account on subsequent ones — the SDK is a thin wrapper over Auth's `POST /{appSlug}/v1/auth/oauth/{provider}` which does the heavy lifting (Apple JWKS verification, issuer pinning, audience validation against the app's configured native client ids, server-side nonce replay protection, account creation / linking).
|
|
145
145
|
|
|
146
|
-
```ts
|
|
146
|
+
```ts before
|
|
147
147
|
import { Auth, AuthHttpError } from "@productcraft/auth";
|
|
148
148
|
|
|
149
149
|
const auth = new Auth();
|
|
@@ -186,7 +186,7 @@ Apple only sends `givenName` / `familyName` on the very first sign-in. Pass them
|
|
|
186
186
|
|
|
187
187
|
### Error handling
|
|
188
188
|
|
|
189
|
-
```ts
|
|
189
|
+
```ts before
|
|
190
190
|
try {
|
|
191
191
|
await consumer.auth.signinWithProvider({ provider: "apple", id_token, nonce });
|
|
192
192
|
} catch (err) {
|
|
@@ -206,7 +206,7 @@ try {
|
|
|
206
206
|
|
|
207
207
|
The Auth API uses a single `POST /{appSlug}/v1/auth/oauth/{provider}` endpoint for every supported IdP — the `provider` URL segment selects the verifier. Once Google is enabled on Auth's side, the SDK call becomes:
|
|
208
208
|
|
|
209
|
-
```ts
|
|
209
|
+
```ts before
|
|
210
210
|
await consumer.auth.signinWithProvider({
|
|
211
211
|
provider: "google",
|
|
212
212
|
id_token: tokenFromGoogleSignInSdk,
|
|
@@ -225,7 +225,7 @@ is one call on `auth.consumer(appSlug).passkeys`. The helpers run
|
|
|
225
225
|
the package anywhere is safe; nothing touches a browser global until you
|
|
226
226
|
call them.
|
|
227
227
|
|
|
228
|
-
```ts
|
|
228
|
+
```ts before
|
|
229
229
|
import { Auth, isPasskeySupported, PasskeyError } from "@productcraft/auth";
|
|
230
230
|
|
|
231
231
|
if (!isPasskeySupported()) hidePasskeyButton(); // false in Node and in insecure contexts
|
|
@@ -292,7 +292,7 @@ Tokens issued before the 2026-05-24 per-app-issuer migration carried `iss: "heim
|
|
|
292
292
|
|
|
293
293
|
### One-line verify (the 80% case)
|
|
294
294
|
|
|
295
|
-
```ts
|
|
295
|
+
```ts before
|
|
296
296
|
import { Auth, JwtExpiredError } from "@productcraft/auth";
|
|
297
297
|
|
|
298
298
|
const auth = new Auth();
|
|
@@ -315,7 +315,7 @@ Behind the scenes: JWKS fetched once, cached in-memory (10 min TTL by default),
|
|
|
315
315
|
|
|
316
316
|
`scope.jwks.getKey` is a [jose-compatible](https://github.com/panva/jose) key resolver — pass it anywhere a `GetKeyFunction` is expected.
|
|
317
317
|
|
|
318
|
-
```ts
|
|
318
|
+
```ts before
|
|
319
319
|
import { jwtVerify } from "jose";
|
|
320
320
|
|
|
321
321
|
const scope = auth.consumer("my-app-slug");
|
|
@@ -336,7 +336,7 @@ Use the companion package [`@productcraft/auth-passport`](https://github.com/cla
|
|
|
336
336
|
npm install @productcraft/auth-passport passport-jwt
|
|
337
337
|
```
|
|
338
338
|
|
|
339
|
-
```ts
|
|
339
|
+
```ts before
|
|
340
340
|
import passportJwt from "passport-jwt";
|
|
341
341
|
import { createPassportSecretOrKeyProvider } from "@productcraft/auth-passport";
|
|
342
342
|
|
|
@@ -387,7 +387,7 @@ PRODUCTCRAFT_AUTH_APP=acme # default slug for auth.consumer()
|
|
|
387
387
|
|
|
388
388
|
## Configuration
|
|
389
389
|
|
|
390
|
-
```ts
|
|
390
|
+
```ts before
|
|
391
391
|
new Auth({
|
|
392
392
|
// Auth credential the SDK presents to Auth
|
|
393
393
|
// Omit to use PRODUCTCRAFT_API_KEY from the environment
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@productcraft/auth",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "Customer auth & EndUsers — sign-in flows, OTP, sessions for ProductCraft Auth. Generated from the production OpenAPI spec.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|