@robelest/convex-auth 0.0.4-preview.29 → 0.0.4-preview.31
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/dist/bin.js +143 -21
- package/dist/browser/index.d.ts +3 -13
- package/dist/browser/index.js +47 -12
- package/dist/browser/navigation.js +1 -1
- package/dist/browser/passkey.js +9 -9
- package/dist/browser/runtime.js +13 -15
- package/dist/client/core/types.d.ts +177 -72
- package/dist/client/core/types.js +6 -0
- package/dist/client/factors/device.js +3 -3
- package/dist/client/factors/totp.js +9 -9
- package/dist/client/index.d.ts +5 -4
- package/dist/client/index.js +122 -63
- package/dist/client/runtime/mutex.js +3 -2
- package/dist/component/_generated/component.d.ts +40 -0
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/http.js +9 -0
- package/dist/component/index.d.ts +1 -1
- package/dist/component/model.d.ts +25 -25
- package/dist/component/model.js +2 -1
- package/dist/component/modules.js +1 -0
- package/dist/component/public/factors/passkeys.js +31 -1
- package/dist/component/public/identity/codes.js +1 -1
- package/dist/component/public/identity/tokens.js +2 -1
- package/dist/component/public/identity/verifiers.js +15 -5
- package/dist/component/public.js +2 -2
- package/dist/component/schema.d.ts +287 -285
- package/dist/component/schema.js +2 -1
- package/dist/core/index.d.ts +10 -24
- package/dist/core/index.js +8 -16
- package/dist/expo/index.d.ts +21 -0
- package/dist/expo/index.js +148 -0
- package/dist/expo/passkey.js +174 -0
- package/dist/providers/apple.d.ts +1 -1
- package/dist/providers/apple.js +6 -8
- package/dist/providers/custom.d.ts +1 -1
- package/dist/providers/custom.js +4 -7
- package/dist/providers/github.d.ts +1 -1
- package/dist/providers/github.js +5 -8
- package/dist/providers/google.d.ts +1 -1
- package/dist/providers/google.js +5 -8
- package/dist/providers/microsoft.d.ts +1 -1
- package/dist/providers/microsoft.js +5 -9
- package/dist/providers/password.d.ts +18 -37
- package/dist/providers/password.js +170 -115
- package/dist/providers/redirect.d.ts +1 -0
- package/dist/providers/redirect.js +20 -0
- package/dist/server/auth.d.ts +9 -24
- package/dist/server/auth.js +4 -8
- package/dist/server/{ctxCache.js → cache/context.js} +2 -2
- package/dist/server/{componentContext.d.ts → component/context.d.ts} +2 -2
- package/dist/server/config.js +10 -0
- package/dist/server/context.js +5 -14
- package/dist/server/contract.d.ts +2 -87
- package/dist/server/contract.js +1 -1
- package/dist/server/cookies.js +25 -1
- package/dist/server/core.js +1 -14
- package/dist/server/device.js +13 -12
- package/dist/server/env.js +10 -2
- package/dist/server/errors.js +24 -1
- package/dist/server/{auth-context.d.ts → facade.d.ts} +4 -46
- package/dist/server/{auth-context.js → facade.js} +23 -11
- package/dist/server/http.d.ts +7 -7
- package/dist/server/http.js +36 -7
- package/dist/server/identity/convex.d.ts +15 -0
- package/dist/server/identity/convex.js +1 -0
- package/dist/server/identity.js +30 -4
- package/dist/server/index.d.ts +5 -2
- package/dist/server/index.js +3 -1
- package/dist/server/mounts.d.ts +246 -93
- package/dist/server/mutations/code.js +7 -1
- package/dist/server/mutations/{credentialsSignIn.js → credentials/signin.js} +10 -10
- package/dist/server/mutations/index.js +1 -1
- package/dist/server/mutations/invalidate.js +11 -1
- package/dist/server/mutations/oauth.js +25 -27
- package/dist/server/mutations/refresh.js +38 -7
- package/dist/server/mutations/signin.js +18 -2
- package/dist/server/mutations/signout.js +32 -10
- package/dist/server/mutations/store.js +2 -2
- package/dist/server/oauth/factory.js +13 -4
- package/dist/server/passkey.js +130 -115
- package/dist/server/prefetch.js +16 -9
- package/dist/server/redirects.js +11 -3
- package/dist/server/refresh.js +6 -1
- package/dist/server/runtime.d.ts +56 -40
- package/dist/server/runtime.js +340 -76
- package/dist/server/services/group.js +4 -0
- package/dist/server/sessions.d.ts +2 -1
- package/dist/server/sessions.js +22 -11
- package/dist/server/signin.js +25 -22
- package/dist/server/sso/domain.d.ts +159 -16
- package/dist/server/sso/domain.js +1 -1
- package/dist/server/sso/http.js +144 -60
- package/dist/server/sso/oidc.js +28 -12
- package/dist/server/sso/policy.js +30 -14
- package/dist/server/sso/provision.js +1 -1
- package/dist/server/sso/saml.js +18 -9
- package/dist/server/sso/scim.js +12 -4
- package/dist/server/sso/shared.js +5 -5
- package/dist/server/telemetry.js +61 -0
- package/dist/server/tokens.js +34 -6
- package/dist/server/totp.js +135 -106
- package/dist/server/types.d.ts +281 -152
- package/dist/server/url.js +1 -1
- package/dist/server/users.js +93 -53
- package/dist/server/utils/span.js +10 -1
- package/dist/server/wellknown.d.ts +130 -0
- package/dist/server/wellknown.js +195 -0
- package/dist/shared/errors.js +0 -1
- package/package.json +39 -4
- package/dist/server/constants.js +0 -6
- package/dist/server/oauth/index.js +0 -12
- package/dist/server/utils/dispatch.js +0 -36
- /package/dist/server/{componentContext.js → component/context.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Value } from "convex/values";
|
|
2
2
|
import { FunctionReference } from "convex/server";
|
|
3
3
|
|
|
4
4
|
//#region src/client/core/types.d.ts
|
|
@@ -22,9 +22,6 @@ interface ConvexTransport {
|
|
|
22
22
|
interface ActionTransport {
|
|
23
23
|
action(action: unknown, args: unknown): Promise<unknown>;
|
|
24
24
|
}
|
|
25
|
-
type SignInApiRef = {
|
|
26
|
-
signIn: AuthApiRefs["signIn"];
|
|
27
|
-
};
|
|
28
25
|
/** Pluggable key-value storage supplied by the host runtime. */
|
|
29
26
|
interface Storage {
|
|
30
27
|
getItem(key: string): string | null | undefined | Promise<string | null | undefined>;
|
|
@@ -35,7 +32,10 @@ interface Storage {
|
|
|
35
32
|
interface LocationRuntime {
|
|
36
33
|
get(): URL | null;
|
|
37
34
|
replace(relativeUrl: string): void | Promise<void>;
|
|
38
|
-
|
|
35
|
+
}
|
|
36
|
+
/** Platform-specific OAuth launch primitive. */
|
|
37
|
+
interface OAuthRuntime {
|
|
38
|
+
open(url: URL): void | Promise<void>;
|
|
39
39
|
}
|
|
40
40
|
/** Cross-context synchronization hooks, such as browser storage events. */
|
|
41
41
|
interface SyncRuntime {
|
|
@@ -59,6 +59,7 @@ interface ClientRuntime {
|
|
|
59
59
|
environment?: "client" | "server";
|
|
60
60
|
storage?: Storage | null;
|
|
61
61
|
location?: LocationRuntime;
|
|
62
|
+
oauth?: OAuthRuntime;
|
|
62
63
|
sync?: SyncRuntime;
|
|
63
64
|
mutex?: MutexRuntime;
|
|
64
65
|
proxy?: ProxyRuntime;
|
|
@@ -69,56 +70,21 @@ interface ClientAdapters {
|
|
|
69
70
|
totp?: TotpClient;
|
|
70
71
|
device?: DeviceClient;
|
|
71
72
|
}
|
|
72
|
-
interface ClientAdapterDeps {
|
|
73
|
-
proxy: string | undefined;
|
|
74
|
-
convex: ConvexTransport;
|
|
75
|
-
requireApiRefs: () => SignInApiRef;
|
|
76
|
-
proxyFetch: (body: Record<string, unknown>) => Promise<unknown>;
|
|
77
|
-
setTokenAndMaybeWait: (args: {
|
|
78
|
-
shouldStore: true;
|
|
79
|
-
tokens: AuthSession | null;
|
|
80
|
-
waitForHandshake: boolean;
|
|
81
|
-
context: {
|
|
82
|
-
provider?: string;
|
|
83
|
-
flow: string;
|
|
84
|
-
};
|
|
85
|
-
} | {
|
|
86
|
-
shouldStore: false;
|
|
87
|
-
tokens: {
|
|
88
|
-
token: string;
|
|
89
|
-
} | null;
|
|
90
|
-
waitForHandshake: boolean;
|
|
91
|
-
context: {
|
|
92
|
-
provider?: string;
|
|
93
|
-
flow: string;
|
|
94
|
-
};
|
|
95
|
-
}) => Promise<boolean>;
|
|
96
|
-
}
|
|
97
|
-
interface ClientAdapterFactories {
|
|
98
|
-
passkey?: (deps: ClientAdapterDeps) => PasskeyClient;
|
|
99
|
-
}
|
|
100
|
-
type AuthSession = {
|
|
101
|
-
token: string;
|
|
102
|
-
refreshToken: string;
|
|
103
|
-
};
|
|
104
73
|
/**
|
|
105
|
-
* Device
|
|
106
|
-
*
|
|
107
|
-
* The device displays the `userCode` (or `verificationUriComplete`) and
|
|
108
|
-
* polls via `auth.device.poll()` until the user authorizes.
|
|
74
|
+
* Device authorization payload returned from the `deviceCode` sign-in flow.
|
|
109
75
|
*/
|
|
110
76
|
type DeviceCodeResult = {
|
|
111
|
-
|
|
112
|
-
userCode: string;
|
|
113
|
-
verificationUri: string;
|
|
114
|
-
verificationUriComplete: string;
|
|
115
|
-
expiresIn: number;
|
|
77
|
+
deviceCode: string;
|
|
78
|
+
userCode: string;
|
|
79
|
+
verificationUri: string;
|
|
80
|
+
verificationUriComplete: string;
|
|
81
|
+
expiresIn: number;
|
|
116
82
|
interval: number;
|
|
117
83
|
};
|
|
118
84
|
/**
|
|
119
85
|
* Result of a `signIn` call.
|
|
120
86
|
*
|
|
121
|
-
* - `kind: "signedIn"` — credentials were accepted and
|
|
87
|
+
* - `kind: "signedIn"` — credentials were accepted and a client session is now available.
|
|
122
88
|
* - `kind: "redirect"` — OAuth flow initiated; redirect the user to `redirect.toString()`.
|
|
123
89
|
* - `kind: "totpRequired"` — credentials valid but 2FA is needed; call `auth.totp.verify()`.
|
|
124
90
|
* - `kind: "deviceCode"` — device flow initiated; display the code and poll via `auth.device.poll()`.
|
|
@@ -163,7 +129,22 @@ type AuthState = {
|
|
|
163
129
|
type AuthApiRefs<HasPasskey extends boolean = boolean, HasTotp extends boolean = boolean, HasDevice extends boolean = boolean> = {
|
|
164
130
|
signIn: FunctionReference<"action", "public", Record<string, Value>, unknown>;
|
|
165
131
|
signOut: FunctionReference<"action", "public", Record<string, Value>, unknown>;
|
|
166
|
-
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Optional hints for {@link PasskeyClient.register}.
|
|
135
|
+
*/
|
|
136
|
+
type PasskeyRegisterOptions = {
|
|
137
|
+
/** Human-readable label for this credential (e.g. `"MacBook Pro"`). */name?: string; /** Email hint stored with the credential. */
|
|
138
|
+
email?: string; /** WebAuthn `user.name` override. */
|
|
139
|
+
userName?: string; /** WebAuthn `user.displayName` override. */
|
|
140
|
+
userDisplayName?: string;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Optional hints for {@link PasskeyClient.signIn}.
|
|
144
|
+
*/
|
|
145
|
+
type PasskeySignInOptions = {
|
|
146
|
+
/** Email hint to filter discoverable credentials. */email?: string; /** Set to `true` for conditional UI (autofill) mode. */
|
|
147
|
+
autofill?: boolean;
|
|
167
148
|
};
|
|
168
149
|
/**
|
|
169
150
|
* Passkey (WebAuthn) client-side helpers.
|
|
@@ -193,7 +174,7 @@ interface PasskeyClient {
|
|
|
193
174
|
* @example
|
|
194
175
|
* ```ts
|
|
195
176
|
* if (await auth.passkey.isAutofillSupported()) {
|
|
196
|
-
* await auth.passkey.
|
|
177
|
+
* await auth.passkey.signIn({ autofill: true });
|
|
197
178
|
* }
|
|
198
179
|
* ```
|
|
199
180
|
*/
|
|
@@ -208,29 +189,54 @@ interface PasskeyClient {
|
|
|
208
189
|
* @param opts.email - Email hint for discoverable credentials.
|
|
209
190
|
* @param opts.userName - WebAuthn `user.name` override.
|
|
210
191
|
* @param opts.userDisplayName - WebAuthn `user.displayName` override.
|
|
211
|
-
|
|
192
|
+
* @returns A {@link SignInResult} — typically `{ kind: "signedIn" }` once a client session is available.
|
|
212
193
|
*
|
|
213
194
|
* @example
|
|
214
195
|
* ```ts
|
|
215
196
|
* const result = await auth.passkey.register({ name: "My laptop" });
|
|
216
197
|
* ```
|
|
217
198
|
*/
|
|
218
|
-
register(opts?:
|
|
199
|
+
register(opts?: PasskeyRegisterOptions): Promise<SignInResult>;
|
|
219
200
|
/**
|
|
220
|
-
*
|
|
201
|
+
* Sign in with an existing passkey and complete the WebAuthn ceremony.
|
|
221
202
|
*
|
|
222
|
-
* @param opts - Optional
|
|
203
|
+
* @param opts - Optional sign-in hints.
|
|
223
204
|
* @param opts.email - Email hint to filter discoverable credentials.
|
|
224
205
|
* @param opts.autofill - Set to `true` for conditional UI (autofill) mode.
|
|
225
|
-
* @returns A {@link SignInResult} — typically `{ kind: "signedIn" }`
|
|
206
|
+
* @returns A {@link SignInResult} — typically `{ kind: "signedIn" }` once a client session is available.
|
|
226
207
|
*
|
|
227
208
|
* @example
|
|
228
209
|
* ```ts
|
|
229
|
-
* const result = await auth.passkey.
|
|
210
|
+
* const result = await auth.passkey.signIn();
|
|
230
211
|
* ```
|
|
231
212
|
*/
|
|
232
|
-
|
|
213
|
+
signIn(opts?: PasskeySignInOptions): Promise<SignInResult>;
|
|
233
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Optional hints for {@link TotpClient.setup}.
|
|
217
|
+
*/
|
|
218
|
+
type TotpSetupOptions = {
|
|
219
|
+
/** Issuer name shown in the authenticator app. */name?: string; /** Account label shown in the authenticator app. */
|
|
220
|
+
accountName?: string;
|
|
221
|
+
};
|
|
222
|
+
/** Result of {@link TotpClient.setup}. */
|
|
223
|
+
type TotpSetupResult = {
|
|
224
|
+
/** `otpauth://` URL — render as a QR code. */uri: string; /** Raw base32-encoded shared secret. */
|
|
225
|
+
secret: string; /** Verifier token to pass to {@link TotpClient.confirm}. */
|
|
226
|
+
verifier: string; /** Factor ID to pass to {@link TotpClient.confirm}. */
|
|
227
|
+
totpId: string;
|
|
228
|
+
};
|
|
229
|
+
/** Params for {@link TotpClient.confirm}. */
|
|
230
|
+
type TotpConfirmParams = {
|
|
231
|
+
/** Six-digit OTP from the authenticator app. */code: string; /** Verifier token from {@link TotpSetupResult.verifier}. */
|
|
232
|
+
verifier: string; /** Factor ID from {@link TotpSetupResult.totpId}. */
|
|
233
|
+
totpId: string;
|
|
234
|
+
};
|
|
235
|
+
/** Params for {@link TotpClient.verify}. */
|
|
236
|
+
type TotpVerifyParams = {
|
|
237
|
+
/** Six-digit OTP from the authenticator app. */code: string; /** Verifier token from a `totpRequired` sign-in result. */
|
|
238
|
+
verifier: string;
|
|
239
|
+
};
|
|
234
240
|
/**
|
|
235
241
|
* TOTP two-factor authentication client-side helpers.
|
|
236
242
|
*
|
|
@@ -256,7 +262,7 @@ interface TotpClient {
|
|
|
256
262
|
* await auth.totp.confirm({ code: userCode, verifier, totpId });
|
|
257
263
|
* ```
|
|
258
264
|
*/
|
|
259
|
-
setup(opts?:
|
|
265
|
+
setup(opts?: TotpSetupOptions): Promise<TotpSetupResult>;
|
|
260
266
|
/**
|
|
261
267
|
* Confirm a newly created TOTP factor with the first authenticator code.
|
|
262
268
|
*
|
|
@@ -272,7 +278,7 @@ interface TotpClient {
|
|
|
272
278
|
* await auth.totp.confirm({ code: "123456", verifier, totpId });
|
|
273
279
|
* ```
|
|
274
280
|
*/
|
|
275
|
-
confirm(opts:
|
|
281
|
+
confirm(opts: TotpConfirmParams): Promise<void>;
|
|
276
282
|
/**
|
|
277
283
|
* Complete a sign-in that is waiting on TOTP verification.
|
|
278
284
|
*
|
|
@@ -290,8 +296,16 @@ interface TotpClient {
|
|
|
290
296
|
* }
|
|
291
297
|
* ```
|
|
292
298
|
*/
|
|
293
|
-
verify(opts:
|
|
299
|
+
verify(opts: TotpVerifyParams): Promise<void>;
|
|
294
300
|
}
|
|
301
|
+
/** Params for {@link DeviceClient.poll}. */
|
|
302
|
+
type DevicePollParams = {
|
|
303
|
+
code: DeviceCodeResult;
|
|
304
|
+
};
|
|
305
|
+
/** Params for {@link DeviceClient.verify}. */
|
|
306
|
+
type DeviceVerifyParams = {
|
|
307
|
+
code: string;
|
|
308
|
+
};
|
|
295
309
|
/**
|
|
296
310
|
* Device authorization (RFC 8628) client-side helpers.
|
|
297
311
|
*
|
|
@@ -319,9 +333,7 @@ interface DeviceClient {
|
|
|
319
333
|
* }
|
|
320
334
|
* ```
|
|
321
335
|
*/
|
|
322
|
-
poll(opts:
|
|
323
|
-
code: DeviceCodeResult;
|
|
324
|
-
}): Promise<void>;
|
|
336
|
+
poll(opts: DevicePollParams): Promise<void>;
|
|
325
337
|
/**
|
|
326
338
|
* Approve a device flow from the verification page using the displayed user code.
|
|
327
339
|
*
|
|
@@ -337,9 +349,7 @@ interface DeviceClient {
|
|
|
337
349
|
* await auth.device.verify({ code: "WDJB-MJHT" });
|
|
338
350
|
* ```
|
|
339
351
|
*/
|
|
340
|
-
verify(opts:
|
|
341
|
-
code: string;
|
|
342
|
-
}): Promise<void>;
|
|
352
|
+
verify(opts: DeviceVerifyParams): Promise<void>;
|
|
343
353
|
}
|
|
344
354
|
/**
|
|
345
355
|
* Extract capability flags from an AuthApiRefs type.
|
|
@@ -377,6 +387,88 @@ interface PendingInvite {
|
|
|
377
387
|
token: string;
|
|
378
388
|
}>;
|
|
379
389
|
}
|
|
390
|
+
/**
|
|
391
|
+
* Discriminated union of params for the password provider's flows.
|
|
392
|
+
*
|
|
393
|
+
* Each branch maps to one of the five password flows: `signUp`, `signIn`,
|
|
394
|
+
* `reset`, `verify`, `change`. Selecting a `flow` literal narrows the
|
|
395
|
+
* accepted params automatically.
|
|
396
|
+
*/
|
|
397
|
+
type PasswordParams = {
|
|
398
|
+
flow: "signUp";
|
|
399
|
+
email: string;
|
|
400
|
+
password: string;
|
|
401
|
+
redirectTo?: string;
|
|
402
|
+
} | {
|
|
403
|
+
flow: "signIn";
|
|
404
|
+
email: string;
|
|
405
|
+
password: string;
|
|
406
|
+
redirectTo?: string;
|
|
407
|
+
} | {
|
|
408
|
+
flow: "reset";
|
|
409
|
+
email: string;
|
|
410
|
+
redirectTo?: string;
|
|
411
|
+
} | {
|
|
412
|
+
flow: "verify";
|
|
413
|
+
email: string;
|
|
414
|
+
code: string; /** When set, completes a `reset` flow by updating the password. Otherwise confirms email. */
|
|
415
|
+
newPassword?: string;
|
|
416
|
+
redirectTo?: string;
|
|
417
|
+
} | {
|
|
418
|
+
flow: "change";
|
|
419
|
+
email: string;
|
|
420
|
+
currentPassword: string;
|
|
421
|
+
newPassword: string;
|
|
422
|
+
redirectTo?: string;
|
|
423
|
+
};
|
|
424
|
+
/** Params for the email (magic link) provider's initiation step. */
|
|
425
|
+
type EmailInitiateParams = {
|
|
426
|
+
email: string;
|
|
427
|
+
redirectTo?: string;
|
|
428
|
+
};
|
|
429
|
+
/**
|
|
430
|
+
* Params for completing a code-based flow (no provider). Used to finalise
|
|
431
|
+
* email magic-link sign-ins and password-reset OTPs when the verification
|
|
432
|
+
* call is made without re-specifying the originating provider.
|
|
433
|
+
*/
|
|
434
|
+
type CodeCompletionParams = {
|
|
435
|
+
code: string;
|
|
436
|
+
redirectTo?: string;
|
|
437
|
+
};
|
|
438
|
+
/** Params for the `sso` provider — requires a connection ID. */
|
|
439
|
+
type SsoParams = {
|
|
440
|
+
connectionId: string;
|
|
441
|
+
redirectTo?: string;
|
|
442
|
+
};
|
|
443
|
+
/** Params for the anonymous provider. Empty / `redirectTo` only. */
|
|
444
|
+
type AnonymousParams = {
|
|
445
|
+
redirectTo?: string;
|
|
446
|
+
};
|
|
447
|
+
/** Default params shape for OAuth-style providers (google, github, etc.). */
|
|
448
|
+
type OAuthSignInParams = {
|
|
449
|
+
redirectTo?: string;
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* Params for `signIn("passkey", ...)`. Direct passkey flows are typically
|
|
453
|
+
* triggered through `auth.passkey.register()` / `auth.passkey.signIn()`
|
|
454
|
+
* — this overload is for advanced callers that bypass the helper.
|
|
455
|
+
*/
|
|
456
|
+
type PasskeySignInParams = {
|
|
457
|
+
redirectTo?: string;
|
|
458
|
+
};
|
|
459
|
+
/**
|
|
460
|
+
* Public signature for `auth.signIn`. The provider literal discriminates the
|
|
461
|
+
* params shape via {@link ParamsForProvider}, and the params slot is
|
|
462
|
+
* automatically optional when the resolved type permits `undefined`.
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```ts
|
|
466
|
+
* auth.signIn("password", { flow: "signIn", email, password });
|
|
467
|
+
* auth.signIn("password", { flow: "change", email, currentPassword, newPassword });
|
|
468
|
+
* auth.signIn("anonymous"); // params optional
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
type SignInOverloads = <P extends string | undefined>(provider: P, ...args: SignInArgs<P>) => Promise<SignInResult>;
|
|
380
472
|
/** Base auth client — always present. */
|
|
381
473
|
interface AuthClientBase {
|
|
382
474
|
/**
|
|
@@ -384,6 +476,8 @@ interface AuthClientBase {
|
|
|
384
476
|
* @readonly
|
|
385
477
|
*/
|
|
386
478
|
readonly state: AuthState;
|
|
479
|
+
/** Restore initial auth state for the current runtime. */
|
|
480
|
+
initialize: () => Promise<void>;
|
|
387
481
|
/** SSR-safe query-param reader. */
|
|
388
482
|
param: (name: string) => string | null;
|
|
389
483
|
/**
|
|
@@ -391,8 +485,12 @@ interface AuthClientBase {
|
|
|
391
485
|
* @readonly
|
|
392
486
|
*/
|
|
393
487
|
readonly invite: PendingInvite | null;
|
|
488
|
+
/** Complete an OAuth callback using a URL or authorization code. */
|
|
489
|
+
completeOAuth: (input: URL | string | {
|
|
490
|
+
code: string;
|
|
491
|
+
}) => Promise<OAuthCompletionResult>;
|
|
394
492
|
/** Start a sign-in flow for a provider. */
|
|
395
|
-
signIn:
|
|
493
|
+
signIn: SignInOverloads;
|
|
396
494
|
/** Sign out and clear local auth state. */
|
|
397
495
|
signOut: () => Promise<void>;
|
|
398
496
|
/** Subscribe to auth state changes. Returns an unsubscribe function. */
|
|
@@ -404,8 +502,8 @@ interface AuthClientBase {
|
|
|
404
502
|
* Framework-agnostic auth client return type.
|
|
405
503
|
*
|
|
406
504
|
* Conditionally includes `totp` and `device` helpers based on the
|
|
407
|
-
* capabilities in the `AuthApiRefs` type.
|
|
408
|
-
* added by {@link
|
|
505
|
+
* capabilities in the `AuthApiRefs` type. Platform-specific `passkey` helpers
|
|
506
|
+
* are added by {@link PlatformAuthClient}.
|
|
409
507
|
*
|
|
410
508
|
* @typeParam Api - An AuthApiRefs type that determines which factor helpers are included.
|
|
411
509
|
*/
|
|
@@ -422,9 +520,11 @@ type AuthClient<Api extends AuthApiRefs<boolean, boolean, boolean> = AuthApiRefs
|
|
|
422
520
|
*
|
|
423
521
|
* @typeParam Api - An AuthApiRefs type that determines which factor helpers are included.
|
|
424
522
|
*/
|
|
425
|
-
type
|
|
523
|
+
type PlatformAuthClient<Api extends AuthApiRefs<boolean, boolean, boolean> = AuthApiRefs> = AuthClient<Api> & (InferCaps<Api>["passkey"] extends true ? {
|
|
426
524
|
passkey: PasskeyClient;
|
|
427
525
|
} : {});
|
|
526
|
+
/** @deprecated Use `PlatformAuthClient`. */
|
|
527
|
+
type BrowserAuthClient<Api extends AuthApiRefs<boolean, boolean, boolean> = AuthApiRefs> = PlatformAuthClient<Api>;
|
|
428
528
|
/**
|
|
429
529
|
* Options for {@link client}.
|
|
430
530
|
*
|
|
@@ -451,8 +551,7 @@ type ClientOptions<Api extends AuthApiRefs<boolean, boolean, boolean> = AuthApiR
|
|
|
451
551
|
*
|
|
452
552
|
* Defaults to `runtime.storage` when provided, otherwise `null`.
|
|
453
553
|
*/
|
|
454
|
-
storage?: Storage | null;
|
|
455
|
-
replaceUrl?: (relativeUrl: string) => void | Promise<void>;
|
|
554
|
+
storage?: Storage | null;
|
|
456
555
|
/**
|
|
457
556
|
* Proxy endpoint used instead of direct Convex auth calls.
|
|
458
557
|
* When set, provide `runtime.proxy` and omit direct `api`/`httpClient`
|
|
@@ -462,6 +561,12 @@ type ClientOptions<Api extends AuthApiRefs<boolean, boolean, boolean> = AuthApiR
|
|
|
462
561
|
tokenSeed?: string | null; /** SSR-safe URL source for reading query parameters. */
|
|
463
562
|
location?: URL | (() => URL | null);
|
|
464
563
|
};
|
|
564
|
+
type OAuthCompletionResult = {
|
|
565
|
+
handled: false;
|
|
566
|
+
} | {
|
|
567
|
+
handled: true;
|
|
568
|
+
cleanupUrl: URL | null;
|
|
569
|
+
};
|
|
465
570
|
//#endregion
|
|
466
|
-
export { AuthApiRefs, AuthClient, AuthState, BrowserAuthClient, ClientOptions, ClientRuntime, DeviceClient, DeviceCodeResult, PasskeyClient, PendingInvite, SignInResult, Storage, TotpClient };
|
|
571
|
+
export { AnonymousParams, AuthApiRefs, AuthClient, AuthState, BrowserAuthClient, ClientOptions, ClientRuntime, CodeCompletionParams, DeviceClient, DeviceCodeResult, DevicePollParams, DeviceVerifyParams, EmailInitiateParams, OAuthCompletionResult, OAuthSignInParams, PasskeyClient, PasskeyRegisterOptions, PasskeySignInOptions, PasskeySignInParams, PasswordParams, PendingInvite, PlatformAuthClient, SignInOverloads, SignInResult, SsoParams, Storage, TotpClient, TotpConfirmParams, TotpSetupOptions, TotpSetupResult, TotpVerifyParams };
|
|
467
572
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
//#region src/client/core/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create a deferred promise that can be resolved or rejected externally.
|
|
4
|
+
*
|
|
5
|
+
* @returns A deferred object containing the promise and control methods.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
2
8
|
function createDeferred() {
|
|
3
9
|
let resolve;
|
|
4
10
|
let reject;
|
|
@@ -45,10 +45,10 @@ function createDeviceClient(deps) {
|
|
|
45
45
|
throw error;
|
|
46
46
|
}
|
|
47
47
|
if (pollResult === null) continue;
|
|
48
|
-
if (isSignedInResult(pollResult) && pollResult.
|
|
48
|
+
if (isSignedInResult(pollResult) && pollResult.session) {
|
|
49
49
|
if (proxy) await setTokenAndMaybeWait({
|
|
50
50
|
shouldStore: false,
|
|
51
|
-
tokens: pollResult.
|
|
51
|
+
tokens: pollResult.session === null ? null : { token: pollResult.session.token },
|
|
52
52
|
waitForHandshake: true,
|
|
53
53
|
context: {
|
|
54
54
|
provider: "device",
|
|
@@ -57,7 +57,7 @@ function createDeviceClient(deps) {
|
|
|
57
57
|
});
|
|
58
58
|
else await setTokenAndMaybeWait({
|
|
59
59
|
shouldStore: true,
|
|
60
|
-
tokens: pollResult.
|
|
60
|
+
tokens: pollResult.session ?? null,
|
|
61
61
|
waitForHandshake: true,
|
|
62
62
|
context: {
|
|
63
63
|
provider: "device",
|
|
@@ -43,7 +43,7 @@ function createTotpClient(deps) {
|
|
|
43
43
|
},
|
|
44
44
|
confirm: async (opts) => {
|
|
45
45
|
const params = {
|
|
46
|
-
flow: "
|
|
46
|
+
flow: "verify",
|
|
47
47
|
code: opts.code,
|
|
48
48
|
totpId: opts.totpId
|
|
49
49
|
};
|
|
@@ -56,9 +56,9 @@ function createTotpClient(deps) {
|
|
|
56
56
|
verifier: opts.verifier
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
|
-
if (isSignedInResult(result$1) && result$1.
|
|
59
|
+
if (isSignedInResult(result$1) && result$1.session) await setTokenAndMaybeWait({
|
|
60
60
|
shouldStore: false,
|
|
61
|
-
tokens: result$1.
|
|
61
|
+
tokens: result$1.session === null ? null : { token: result$1.session.token },
|
|
62
62
|
waitForHandshake: true,
|
|
63
63
|
context: {
|
|
64
64
|
provider: "totp",
|
|
@@ -72,9 +72,9 @@ function createTotpClient(deps) {
|
|
|
72
72
|
params,
|
|
73
73
|
verifier: opts.verifier
|
|
74
74
|
});
|
|
75
|
-
if (isSignedInResult(result) && result.
|
|
75
|
+
if (isSignedInResult(result) && result.session) await setTokenAndMaybeWait({
|
|
76
76
|
shouldStore: true,
|
|
77
|
-
tokens: result.
|
|
77
|
+
tokens: result.session ?? null,
|
|
78
78
|
waitForHandshake: true,
|
|
79
79
|
context: {
|
|
80
80
|
provider: "totp",
|
|
@@ -96,9 +96,9 @@ function createTotpClient(deps) {
|
|
|
96
96
|
verifier: opts.verifier
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
|
-
if (isSignedInResult(result$1) && result$1.
|
|
99
|
+
if (isSignedInResult(result$1) && result$1.session) await setTokenAndMaybeWait({
|
|
100
100
|
shouldStore: false,
|
|
101
|
-
tokens: result$1.
|
|
101
|
+
tokens: result$1.session === null ? null : { token: result$1.session.token },
|
|
102
102
|
waitForHandshake: true,
|
|
103
103
|
context: {
|
|
104
104
|
provider: "totp",
|
|
@@ -112,9 +112,9 @@ function createTotpClient(deps) {
|
|
|
112
112
|
params,
|
|
113
113
|
verifier: opts.verifier
|
|
114
114
|
});
|
|
115
|
-
if (isSignedInResult(result) && result.
|
|
115
|
+
if (isSignedInResult(result) && result.session) await setTokenAndMaybeWait({
|
|
116
116
|
shouldStore: true,
|
|
117
|
-
tokens: result.
|
|
117
|
+
tokens: result.session ?? null,
|
|
118
118
|
waitForHandshake: true,
|
|
119
119
|
context: {
|
|
120
120
|
provider: "totp",
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { AuthApiRefs, AuthClient, AuthState, BrowserAuthClient, ClientOptions, ClientRuntime, DeviceClient, DeviceCodeResult, PasskeyClient, PendingInvite, SignInResult, Storage, TotpClient } from "./core/types.js";
|
|
1
|
+
import { AnonymousParams, AuthApiRefs, AuthClient, AuthState, BrowserAuthClient, ClientOptions, ClientRuntime, CodeCompletionParams, DeviceClient, DeviceCodeResult, DevicePollParams, DeviceVerifyParams, EmailInitiateParams, OAuthCompletionResult, OAuthSignInParams, PasskeyClient, PasskeyRegisterOptions, PasskeySignInOptions, PasskeySignInParams, PasswordParams, PendingInvite, PlatformAuthClient, SignInOverloads, SignInResult, SsoParams, Storage, TotpClient, TotpConfirmParams, TotpSetupOptions, TotpSetupResult, TotpVerifyParams } from "./core/types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/client/index.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Create a framework-agnostic auth client.
|
|
6
6
|
*
|
|
7
7
|
* Returns an object with `signIn`, `signOut`, `onChange`, `state`, and any
|
|
8
|
-
* factor helpers enabled by your configured providers.
|
|
9
|
-
* passkey support is added by
|
|
8
|
+
* factor helpers enabled by your configured providers. Platform-specific
|
|
9
|
+
* passkey support is added by higher-level entrypoints such as
|
|
10
|
+
* `@robelest/convex-auth/browser`.
|
|
10
11
|
*
|
|
11
12
|
* ### SPA mode (default)
|
|
12
13
|
*
|
|
@@ -43,5 +44,5 @@ import { AuthApiRefs, AuthClient, AuthState, BrowserAuthClient, ClientOptions, C
|
|
|
43
44
|
*/
|
|
44
45
|
declare function client<Api extends AuthApiRefs<boolean, boolean, boolean> = AuthApiRefs>(options: ClientOptions<Api>): AuthClient<Api>;
|
|
45
46
|
//#endregion
|
|
46
|
-
export { type AuthApiRefs, type AuthClient, type AuthState, type BrowserAuthClient, type ClientOptions, type ClientRuntime, type DeviceClient, type DeviceCodeResult, type PasskeyClient, type PendingInvite, type SignInResult, type Storage, type TotpClient, client };
|
|
47
|
+
export { type AnonymousParams, type AuthApiRefs, type AuthClient, type AuthState, type BrowserAuthClient, type ClientOptions, type ClientRuntime, type CodeCompletionParams, type DeviceClient, type DeviceCodeResult, type DevicePollParams, type DeviceVerifyParams, type EmailInitiateParams, type OAuthCompletionResult, type OAuthSignInParams, type PasskeyClient, type PasskeyRegisterOptions, type PasskeySignInOptions, type PasskeySignInParams, type PasswordParams, type PendingInvite, type PlatformAuthClient, type SignInOverloads, type SignInResult, type SsoParams, type Storage, type TotpClient, type TotpConfirmParams, type TotpSetupOptions, type TotpSetupResult, type TotpVerifyParams, client };
|
|
47
48
|
//# sourceMappingURL=index.d.ts.map
|