@robelest/convex-auth 0.0.4-preview.7 → 0.0.4-preview.8
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/client/index.d.ts +26 -26
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +53 -42
- package/dist/client/index.js.map +1 -1
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/convex.config.d.ts.map +1 -1
- package/dist/component/providers/credentials.d.ts +2 -2
- package/dist/component/providers/credentials.d.ts.map +1 -1
- package/dist/component/providers/email.js +2 -2
- package/dist/component/providers/email.js.map +1 -1
- package/dist/component/public.d.ts.map +1 -1
- package/dist/component/public.js +182 -163
- package/dist/component/public.js.map +1 -1
- package/dist/component/schema.d.ts +87 -87
- package/dist/component/schema.js +48 -48
- package/dist/component/schema.js.map +1 -1
- package/dist/component/server/auth.d.ts +15 -15
- package/dist/component/server/auth.d.ts.map +1 -1
- package/dist/component/server/auth.js +1 -1
- package/dist/component/server/auth.js.map +1 -1
- package/dist/component/server/implementation/index.d.ts +20 -20
- package/dist/component/server/implementation/index.js +1 -1
- package/dist/component/server/implementation/index.js.map +1 -1
- package/dist/component/server/implementation/mutations/code.js.map +1 -1
- package/dist/component/server/implementation/mutations/index.js +1 -1
- package/dist/component/server/implementation/mutations/index.js.map +1 -1
- package/dist/component/server/implementation/mutations/invalidate.js.map +1 -1
- package/dist/component/server/implementation/mutations/refresh.js.map +1 -1
- package/dist/component/server/implementation/mutations/register.js.map +1 -1
- package/dist/component/server/implementation/mutations/retrieve.js.map +1 -1
- package/dist/component/server/implementation/mutations/signature.js.map +1 -1
- package/dist/component/server/implementation/mutations/signin.js.map +1 -1
- package/dist/component/server/implementation/mutations/signout.js.map +1 -1
- package/dist/component/server/implementation/mutations/store.js +1 -1
- package/dist/component/server/implementation/mutations/store.js.map +1 -1
- package/dist/component/server/implementation/mutations/verifier.js.map +1 -1
- package/dist/component/server/implementation/mutations/verify.js.map +1 -1
- package/dist/component/server/implementation/ratelimit.js +9 -9
- package/dist/component/server/implementation/ratelimit.js.map +1 -1
- package/dist/component/server/implementation/refresh.js.map +1 -1
- package/dist/component/server/implementation/sessions.js.map +1 -1
- package/dist/component/server/implementation/signin.js.map +1 -1
- package/dist/component/server/implementation/tokens.js.map +1 -1
- package/dist/component/server/implementation/types.js.map +1 -1
- package/dist/component/server/implementation/users.js.map +1 -1
- package/dist/component/server/types.d.ts +17 -16
- package/dist/component/server/types.d.ts.map +1 -1
- package/dist/providers/anonymous.d.ts +2 -6
- package/dist/providers/anonymous.d.ts.map +1 -1
- package/dist/providers/anonymous.js +1 -7
- package/dist/providers/anonymous.js.map +1 -1
- package/dist/providers/credentials.d.ts +3 -5
- package/dist/providers/credentials.d.ts.map +1 -1
- package/dist/providers/credentials.js +1 -5
- package/dist/providers/credentials.js.map +1 -1
- package/dist/providers/device.d.ts +1 -5
- package/dist/providers/device.d.ts.map +1 -1
- package/dist/providers/device.js +1 -7
- package/dist/providers/device.js.map +1 -1
- package/dist/providers/email.d.ts +2 -2
- package/dist/providers/email.d.ts.map +1 -1
- package/dist/providers/email.js +2 -2
- package/dist/providers/email.js.map +1 -1
- package/dist/providers/passkey.d.ts +1 -5
- package/dist/providers/passkey.d.ts.map +1 -1
- package/dist/providers/passkey.js +1 -7
- package/dist/providers/passkey.js.map +1 -1
- package/dist/providers/password.d.ts +2 -6
- package/dist/providers/password.d.ts.map +1 -1
- package/dist/providers/password.js +1 -7
- package/dist/providers/password.js.map +1 -1
- package/dist/providers/phone.d.ts +1 -1
- package/dist/providers/phone.d.ts.map +1 -1
- package/dist/providers/phone.js +1 -1
- package/dist/providers/phone.js.map +1 -1
- package/dist/providers/totp.d.ts +1 -5
- package/dist/providers/totp.d.ts.map +1 -1
- package/dist/providers/totp.js +1 -7
- package/dist/providers/totp.js.map +1 -1
- package/dist/server/auth.d.ts +15 -15
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +1 -1
- package/dist/server/auth.js.map +1 -1
- package/dist/server/implementation/index.d.ts +26 -26
- package/dist/server/implementation/index.js +1 -1
- package/dist/server/implementation/index.js.map +1 -1
- package/dist/server/implementation/mutations/account.d.ts +8 -8
- package/dist/server/implementation/mutations/code.d.ts +9 -9
- package/dist/server/implementation/mutations/code.js.map +1 -1
- package/dist/server/implementation/mutations/index.d.ts +93 -93
- package/dist/server/implementation/mutations/index.js +1 -1
- package/dist/server/implementation/mutations/index.js.map +1 -1
- package/dist/server/implementation/mutations/invalidate.d.ts +4 -4
- package/dist/server/implementation/mutations/invalidate.js.map +1 -1
- package/dist/server/implementation/mutations/oauth.d.ts +6 -6
- package/dist/server/implementation/mutations/oauth.d.ts.map +1 -1
- package/dist/server/implementation/mutations/refresh.d.ts +3 -3
- package/dist/server/implementation/mutations/refresh.d.ts.map +1 -1
- package/dist/server/implementation/mutations/refresh.js.map +1 -1
- package/dist/server/implementation/mutations/register.d.ts +14 -14
- package/dist/server/implementation/mutations/register.d.ts.map +1 -1
- package/dist/server/implementation/mutations/register.js.map +1 -1
- package/dist/server/implementation/mutations/retrieve.d.ts +10 -10
- package/dist/server/implementation/mutations/retrieve.d.ts.map +1 -1
- package/dist/server/implementation/mutations/retrieve.js.map +1 -1
- package/dist/server/implementation/mutations/signature.d.ts +4 -4
- package/dist/server/implementation/mutations/signature.d.ts.map +1 -1
- package/dist/server/implementation/mutations/signature.js.map +1 -1
- package/dist/server/implementation/mutations/signin.d.ts +5 -5
- package/dist/server/implementation/mutations/signin.d.ts.map +1 -1
- package/dist/server/implementation/mutations/signin.js.map +1 -1
- package/dist/server/implementation/mutations/signout.d.ts +2 -2
- package/dist/server/implementation/mutations/signout.js.map +1 -1
- package/dist/server/implementation/mutations/store.js +1 -1
- package/dist/server/implementation/mutations/store.js.map +1 -1
- package/dist/server/implementation/mutations/verifier.d.ts +1 -1
- package/dist/server/implementation/mutations/verifier.js.map +1 -1
- package/dist/server/implementation/mutations/verify.d.ts +7 -7
- package/dist/server/implementation/mutations/verify.d.ts.map +1 -1
- package/dist/server/implementation/mutations/verify.js.map +1 -1
- package/dist/server/implementation/ratelimit.js +9 -9
- package/dist/server/implementation/ratelimit.js.map +1 -1
- package/dist/server/implementation/refresh.d.ts +9 -9
- package/dist/server/implementation/refresh.d.ts.map +1 -1
- package/dist/server/implementation/refresh.js.map +1 -1
- package/dist/server/implementation/sessions.d.ts +8 -8
- package/dist/server/implementation/sessions.js.map +1 -1
- package/dist/server/implementation/signin.d.ts +1 -1
- package/dist/server/implementation/signin.js.map +1 -1
- package/dist/server/implementation/tokens.d.ts +2 -2
- package/dist/server/implementation/tokens.js.map +1 -1
- package/dist/server/implementation/types.d.ts +4 -4
- package/dist/server/implementation/types.js.map +1 -1
- package/dist/server/implementation/users.d.ts +5 -5
- package/dist/server/implementation/users.js.map +1 -1
- package/dist/server/index.d.ts +14 -14
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +36 -36
- package/dist/server/index.js.map +1 -1
- package/dist/server/providers.d.ts +6 -5
- package/dist/server/providers.d.ts.map +1 -1
- package/dist/server/types.d.ts +17 -16
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/version.d.ts +1 -1
- package/dist/server/version.js +1 -1
- package/dist/server/version.js.map +1 -1
- package/package.json +1 -1
- package/src/client/index.ts +84 -63
- package/src/component/public.ts +232 -211
- package/src/component/schema.ts +61 -61
- package/src/providers/anonymous.ts +1 -14
- package/src/providers/credentials.ts +2 -12
- package/src/providers/device.ts +0 -13
- package/src/providers/email.ts +2 -2
- package/src/providers/passkey.ts +0 -13
- package/src/providers/password.ts +3 -16
- package/src/providers/phone.ts +1 -1
- package/src/providers/totp.ts +0 -13
- package/src/server/auth.ts +4 -4
- package/src/server/implementation/index.ts +11 -11
- package/src/server/implementation/mutations/code.ts +2 -2
- package/src/server/implementation/mutations/index.ts +1 -1
- package/src/server/implementation/mutations/invalidate.ts +1 -1
- package/src/server/implementation/mutations/refresh.ts +1 -1
- package/src/server/implementation/mutations/register.ts +5 -5
- package/src/server/implementation/mutations/retrieve.ts +3 -3
- package/src/server/implementation/mutations/signature.ts +1 -1
- package/src/server/implementation/mutations/signin.ts +2 -2
- package/src/server/implementation/mutations/signout.ts +2 -2
- package/src/server/implementation/mutations/store.ts +1 -1
- package/src/server/implementation/mutations/verifier.ts +1 -1
- package/src/server/implementation/mutations/verify.ts +1 -1
- package/src/server/implementation/ratelimit.ts +13 -12
- package/src/server/implementation/refresh.ts +23 -23
- package/src/server/implementation/sessions.ts +11 -11
- package/src/server/implementation/signin.ts +2 -2
- package/src/server/implementation/tokens.ts +2 -2
- package/src/server/implementation/types.ts +4 -4
- package/src/server/implementation/users.ts +13 -13
- package/src/server/index.ts +54 -44
- package/src/server/types.ts +18 -16
- package/src/server/version.ts +1 -1
package/dist/client/index.d.ts
CHANGED
|
@@ -27,19 +27,19 @@ interface Storage {
|
|
|
27
27
|
/**
|
|
28
28
|
* Device code response returned when signing in with the `"device"` provider.
|
|
29
29
|
*
|
|
30
|
-
* The device displays the `userCode` (or `
|
|
30
|
+
* The device displays the `userCode` (or `verification_uri_complete`) and
|
|
31
31
|
* polls via `auth.device.poll()` until the user authorizes.
|
|
32
32
|
*/
|
|
33
33
|
type DeviceCodeResult = {
|
|
34
34
|
/** High-entropy device code used for polling (keep secret). */deviceCode: string; /** Short human-readable code the user enters (e.g. "WDJB-MJHT"). */
|
|
35
35
|
userCode: string; /** Base verification URL (e.g. "https://myapp.com/device"). */
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
verification_uri: string; /** Verification URL with user code pre-filled as `?code=XXXX-XXXX`. */
|
|
37
|
+
verification_uri_complete: string; /** Lifetime of the codes in seconds. */
|
|
38
38
|
expiresIn: number; /** Minimum polling interval in seconds. */
|
|
39
39
|
interval: number;
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
|
-
* Result of a `
|
|
42
|
+
* Result of a `sign_in` call.
|
|
43
43
|
*
|
|
44
44
|
* - `signingIn: true` — credentials were accepted and the user is authenticated.
|
|
45
45
|
* - `redirect` — OAuth flow initiated; redirect the user to `redirect.toString()`.
|
|
@@ -54,7 +54,7 @@ type SignInResult = {
|
|
|
54
54
|
deviceCode?: DeviceCodeResult; /** Opaque verifier for multi-step flows (pass to `totp.verify` or passkey phase 2). */
|
|
55
55
|
verifier?: string;
|
|
56
56
|
};
|
|
57
|
-
/** Reactive auth state snapshot returned by `auth.state` and `auth.
|
|
57
|
+
/** Reactive auth state snapshot returned by `auth.state` and `auth.on_change`. */
|
|
58
58
|
type AuthState = {
|
|
59
59
|
/** High-level auth phase for deterministic UI state handling. */phase: "loading" | "handshake" | "authenticated" | "unauthenticated"; /** `true` during initial hydration before the first token is resolved. */
|
|
60
60
|
isLoading: boolean; /** `true` only after Convex confirms authentication with the backend. */
|
|
@@ -73,21 +73,21 @@ type ClientOptions = {
|
|
|
73
73
|
* Key-value storage for persisting tokens.
|
|
74
74
|
*
|
|
75
75
|
* - Defaults to `localStorage` in SPA mode.
|
|
76
|
-
* - Defaults to `null` (in-memory only) when `
|
|
76
|
+
* - Defaults to `null` (in-memory only) when `proxy_path` is set,
|
|
77
77
|
* since httpOnly cookies handle persistence.
|
|
78
78
|
*/
|
|
79
79
|
storage?: Storage | null; /** Override how the URL bar is updated after OAuth code exchange. */
|
|
80
|
-
|
|
80
|
+
replace_url?: (relative_url: string) => void | Promise<void>;
|
|
81
81
|
/**
|
|
82
82
|
* SSR proxy endpoint (e.g. `"/api/auth"`).
|
|
83
83
|
*
|
|
84
|
-
* When set, `
|
|
84
|
+
* When set, `sign_in`/`sign_out`/token refresh POST to this URL
|
|
85
85
|
* (with `credentials: "include"`) instead of calling Convex directly.
|
|
86
86
|
* The server handles httpOnly cookies for token persistence.
|
|
87
87
|
*
|
|
88
|
-
* Pair with {@link ClientOptions.
|
|
88
|
+
* Pair with {@link ClientOptions.token_seed} for flash-free SSR hydration.
|
|
89
89
|
*/
|
|
90
|
-
|
|
90
|
+
proxy_path?: string;
|
|
91
91
|
/**
|
|
92
92
|
* JWT from server-side hydration.
|
|
93
93
|
*
|
|
@@ -95,12 +95,12 @@ type ClientOptions = {
|
|
|
95
95
|
* and passes it to the client during SSR. This avoids a loading
|
|
96
96
|
* flash on first render — the client is immediately authenticated.
|
|
97
97
|
*/
|
|
98
|
-
|
|
98
|
+
token_seed?: string | null;
|
|
99
99
|
};
|
|
100
100
|
/**
|
|
101
101
|
* Create a framework-agnostic auth client.
|
|
102
102
|
*
|
|
103
|
-
* Returns an object with `
|
|
103
|
+
* Returns an object with `sign_in`, `sign_out`, `on_change`, `state`,
|
|
104
104
|
* `passkey`, and `totp` — everything needed for client-side auth.
|
|
105
105
|
*
|
|
106
106
|
* ### SPA mode (default)
|
|
@@ -118,8 +118,8 @@ type ClientOptions = {
|
|
|
118
118
|
* ```ts
|
|
119
119
|
* const auth = client({
|
|
120
120
|
* convex,
|
|
121
|
-
*
|
|
122
|
-
*
|
|
121
|
+
* proxy_path: '/api/auth',
|
|
122
|
+
* token_seed: tokenFromServer, // JWT read from httpOnly cookie during SSR
|
|
123
123
|
* });
|
|
124
124
|
* ```
|
|
125
125
|
*
|
|
@@ -128,13 +128,13 @@ type ClientOptions = {
|
|
|
128
128
|
* holds the JWT in memory only.
|
|
129
129
|
*
|
|
130
130
|
* @param options - Client configuration. See {@link ClientOptions}.
|
|
131
|
-
* @returns Auth client with `
|
|
131
|
+
* @returns Auth client with `sign_in`, `sign_out`, `on_change`, `state`, `passkey`, and `totp`.
|
|
132
132
|
*/
|
|
133
133
|
declare function client(options: ClientOptions): {
|
|
134
134
|
/** Current auth state snapshot. */readonly state: AuthState; /** Sign in with a provider. See {@link SignInResult} for return shape. */
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
sign_in: (provider?: string, args?: FormData | Record<string, Value>) => Promise<SignInResult>; /** Sign out and clear all token state. */
|
|
136
|
+
sign_out: () => Promise<void>; /** Subscribe to auth state changes. Returns an unsubscribe function. */
|
|
137
|
+
on_change: (cb: (state: AuthState) => void) => (() => void); /** Passkey (WebAuthn) authentication helpers. */
|
|
138
138
|
passkey: {
|
|
139
139
|
/**
|
|
140
140
|
* Check if WebAuthn passkeys are supported in the current environment.
|
|
@@ -246,8 +246,8 @@ declare function client(options: ClientOptions): {
|
|
|
246
246
|
*
|
|
247
247
|
* Called after a credentials sign-in returns `totpRequired: true`.
|
|
248
248
|
*
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
* ```ts
|
|
250
|
+
* const result = await auth.sign_in("password", { email, password });
|
|
251
251
|
* if (result.totpRequired) {
|
|
252
252
|
* await auth.totp.verify({ code: "123456", verifier: result.verifier! });
|
|
253
253
|
* }
|
|
@@ -262,19 +262,19 @@ declare function client(options: ClientOptions): {
|
|
|
262
262
|
/**
|
|
263
263
|
* Poll for device authorization status.
|
|
264
264
|
*
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
* The device calls this repeatedly (respecting `interval`) after
|
|
266
|
+
* initiating a device flow via `sign_in("device")`. Returns when
|
|
267
267
|
* the user authorizes, or throws on timeout/denial.
|
|
268
268
|
*
|
|
269
|
-
|
|
270
|
-
|
|
269
|
+
* ```ts
|
|
270
|
+
* const result = await auth.sign_in("device");
|
|
271
271
|
* const { deviceCode } = result;
|
|
272
272
|
* // Display deviceCode.userCode to the user, then poll:
|
|
273
273
|
* await auth.device.poll(deviceCode);
|
|
274
274
|
* // User is now signed in
|
|
275
275
|
* ```
|
|
276
|
-
|
|
277
|
-
|
|
276
|
+
*
|
|
277
|
+
* @param code - The {@link DeviceCodeResult} from `sign_in("device")`.
|
|
278
278
|
* @returns Resolves when the device is authorized and tokens are stored.
|
|
279
279
|
* @throws When the code expires, is denied, or polling encounters an error.
|
|
280
280
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/client/index.ts"],"mappings":";;;;;;AAU0B;;;;;;;UAWhB,eAAA;EACR,MAAA,CAAO,MAAA,OAAa,IAAA,QAAY,OAAA;EAChC,OAAA,CACE,UAAA,GAAa,IAAA;IACX,iBAAA;EAAA,MACI,OAAA,6BACN,QAAA,IAAY,eAAA;EAEd,SAAA;AAAA;;UAIe,OAAA;EACf,OAAA,CACE,GAAA,uCAC6B,OAAA;EAC/B,OAAA,CAAQ,GAAA,UAAa,KAAA,kBAAuB,OAAA;EAC5C,UAAA,CAAW,GAAA,kBAAqB,OAAA;AAAA;;;;;;;KActB,gBAAA;EAjBR,+DAmBF,UAAA,UAjBA;EAmBA,QAAA,UAnBqB;EAqBrB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/client/index.ts"],"mappings":";;;;;;AAU0B;;;;;;;UAWhB,eAAA;EACR,MAAA,CAAO,MAAA,OAAa,IAAA,QAAY,OAAA;EAChC,OAAA,CACE,UAAA,GAAa,IAAA;IACX,iBAAA;EAAA,MACI,OAAA,6BACN,QAAA,IAAY,eAAA;EAEd,SAAA;AAAA;;UAIe,OAAA;EACf,OAAA,CACE,GAAA,uCAC6B,OAAA;EAC/B,OAAA,CAAQ,GAAA,UAAa,KAAA,kBAAuB,OAAA;EAC5C,UAAA,CAAW,GAAA,kBAAqB,OAAA;AAAA;;;;;;;KActB,gBAAA;EAjBR,+DAmBF,UAAA,UAjBA;EAmBA,QAAA,UAnBqB;EAqBrB,gBAAA,UApBA;EAsBA,yBAAA,UAtBgC;EAwBhC,SAAA,UAxBuC;EA0BvC,QAAA;AAAA;;;;;;;;;;KAYU,YAAA;EAAA,mEAEV,SAAA;EAEA,QAAA,GAAW,GAAA,EAFX;EAIA,YAAA,YAFW;EAIX,UAAA,GAAa,gBAAA,EAAb;EAEA,QAAA;AAAA;;KAIU,SAAA;EAAA,iEAEV,KAAA;EAEA,SAAA,WAFA;EAIA,eAAA;EAEA,KAAA;AAAA;;KAIU,aAAA;EAAa,iEAEvB,MAAA,EAAQ,eAAA;EAAA;;;;EAKR,GAAA;EALA;;;;;;;EAaA,OAAA,GAAU,OAAA,SAYV;EAVA,WAAA,IAAe,YAAA,oBAAgC,OAAA;EAkBrC;;AA6EZ;;;;;;;EArFE,UAAA;EAkmBW;;;;;;;EA1lBX,UAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6Ec,MAAA,CAAO,OAAA,EAAS,aAAA;EAq6BxB,mDAwgBS,SAAA,EAtgBV;+BA5Zc,IAAA,GACV,QAAA,GAAW,MAAA,SAAe,KAAA,MAChC,OAAA,CAAQ,YAAA;iCAgjBkB;mBAzTL,KAAA,EAAO,SAAA,4BA0T1B;;;;;;;;;;;;;;;+BAlM4B,OAAA;;;;;;;;;;;;;;;;;;;;;;;MAsC3B,IAAA;MACA,KAAA;MACA,QAAA;MACA,eAAA;IAAA,MAED,OAAA,CAAQ,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAsJA,KAAA;MAAgB,QAAA;IAAA,MACxB,OAAA,CAAQ,YAAA;EAAA;;;;;;;;;;;;;;MAwHA,IAAA;MAAe,WAAA;IAAA,MACvB,OAAA;MAAU,GAAA;MAAa,MAAA;MAAgB,QAAA;MAAkB,MAAA;IAAA;;;;;;;;;MA4B1D,IAAA;MACA,QAAA;MACA,MAAA;IAAA,MACE,OAAA;;;;;;;;;;;;;;MAkDmB,IAAA;MAAc,QAAA;IAAA,MAAqB,OAAA;EAAA;;;;;;;;;;;;;;;;;;;;;iBA0DvC,gBAAA,KAAmB,OAAA;;;;;;;;;;;;;;kCAqFJ,OAAA;EAAA"}
|
package/dist/client/index.js
CHANGED
|
@@ -25,7 +25,7 @@ function resolveUrl(convex, explicit) {
|
|
|
25
25
|
/**
|
|
26
26
|
* Create a framework-agnostic auth client.
|
|
27
27
|
*
|
|
28
|
-
* Returns an object with `
|
|
28
|
+
* Returns an object with `sign_in`, `sign_out`, `on_change`, `state`,
|
|
29
29
|
* `passkey`, and `totp` — everything needed for client-side auth.
|
|
30
30
|
*
|
|
31
31
|
* ### SPA mode (default)
|
|
@@ -43,8 +43,8 @@ function resolveUrl(convex, explicit) {
|
|
|
43
43
|
* ```ts
|
|
44
44
|
* const auth = client({
|
|
45
45
|
* convex,
|
|
46
|
-
*
|
|
47
|
-
*
|
|
46
|
+
* proxy_path: '/api/auth',
|
|
47
|
+
* token_seed: tokenFromServer, // JWT read from httpOnly cookie during SSR
|
|
48
48
|
* });
|
|
49
49
|
* ```
|
|
50
50
|
*
|
|
@@ -53,12 +53,13 @@ function resolveUrl(convex, explicit) {
|
|
|
53
53
|
* holds the JWT in memory only.
|
|
54
54
|
*
|
|
55
55
|
* @param options - Client configuration. See {@link ClientOptions}.
|
|
56
|
-
* @returns Auth client with `
|
|
56
|
+
* @returns Auth client with `sign_in`, `sign_out`, `on_change`, `state`, `passkey`, and `totp`.
|
|
57
57
|
*/
|
|
58
58
|
function client(options) {
|
|
59
|
-
const { convex,
|
|
59
|
+
const { convex, proxy_path } = options;
|
|
60
|
+
const proxy = proxy_path;
|
|
60
61
|
const storage = options.storage !== void 0 ? options.storage : proxy ? null : typeof window === "undefined" ? null : window.localStorage;
|
|
61
|
-
const
|
|
62
|
+
const replace_url = options.replace_url ?? ((url$1) => {
|
|
62
63
|
if (typeof window !== "undefined") window.history.replaceState({}, "", url$1);
|
|
63
64
|
});
|
|
64
65
|
const url = proxy ? void 0 : resolveUrl(convex, options.url);
|
|
@@ -67,7 +68,7 @@ function client(options) {
|
|
|
67
68
|
const subscribers = /* @__PURE__ */ new Set();
|
|
68
69
|
let disposeStorageListener = null;
|
|
69
70
|
const httpClient = proxy ? null : new ConvexHttpClient(url);
|
|
70
|
-
const serverToken = typeof options.
|
|
71
|
+
const serverToken = typeof options.token_seed === "string" && options.token_seed.trim().length > 0 ? options.token_seed : null;
|
|
71
72
|
const hasServerToken = serverToken !== null;
|
|
72
73
|
let token = serverToken;
|
|
73
74
|
let isLoading = !hasServerToken;
|
|
@@ -284,7 +285,7 @@ function client(options) {
|
|
|
284
285
|
const verifyCode = async (args) => {
|
|
285
286
|
let lastError;
|
|
286
287
|
for (let retry = 0; retry <= RETRY_BACKOFF.length; retry++) try {
|
|
287
|
-
return await httpClient.action("auth:
|
|
288
|
+
return await httpClient.action("auth/session:start", "code" in args ? {
|
|
288
289
|
params: { code: args.code },
|
|
289
290
|
verifier: args.verifier
|
|
290
291
|
} : args);
|
|
@@ -306,6 +307,16 @@ function client(options) {
|
|
|
306
307
|
});
|
|
307
308
|
return tokens !== null;
|
|
308
309
|
};
|
|
310
|
+
const normalizeDeviceCodeResult = (device_code) => {
|
|
311
|
+
return {
|
|
312
|
+
deviceCode: device_code.deviceCode,
|
|
313
|
+
userCode: device_code.userCode,
|
|
314
|
+
verification_uri: device_code.verification_uri ?? device_code.verificationUri,
|
|
315
|
+
verification_uri_complete: device_code.verification_uri_complete ?? device_code.verificationUriComplete,
|
|
316
|
+
expiresIn: device_code.expiresIn,
|
|
317
|
+
interval: device_code.interval
|
|
318
|
+
};
|
|
319
|
+
};
|
|
309
320
|
/**
|
|
310
321
|
* Sign in with a provider.
|
|
311
322
|
*
|
|
@@ -317,12 +328,12 @@ function client(options) {
|
|
|
317
328
|
*
|
|
318
329
|
* @example Email magic link
|
|
319
330
|
* ```ts
|
|
320
|
-
* await auth.
|
|
331
|
+
* await auth.sign_in('email', { email: 'user@example.com' });
|
|
321
332
|
* ```
|
|
322
333
|
*
|
|
323
334
|
* @example Password
|
|
324
335
|
* ```ts
|
|
325
|
-
* const result = await auth.
|
|
336
|
+
* const result = await auth.sign_in('password', { email, password, flow: 'signIn' });
|
|
326
337
|
* if (result.totpRequired) {
|
|
327
338
|
* await auth.totp.verify({ code: totpCode, verifier: result.verifier! });
|
|
328
339
|
* }
|
|
@@ -330,7 +341,7 @@ function client(options) {
|
|
|
330
341
|
*
|
|
331
342
|
* @example OAuth (triggers redirect)
|
|
332
343
|
* ```ts
|
|
333
|
-
* await auth.
|
|
344
|
+
* await auth.sign_in('google'); // redirects to Google
|
|
334
345
|
* ```
|
|
335
346
|
*/
|
|
336
347
|
const signIn = async (provider, args) => {
|
|
@@ -341,7 +352,7 @@ function client(options) {
|
|
|
341
352
|
const flow = typeof params.flow === "string" && params.flow.length > 0 ? params.flow : "signIn";
|
|
342
353
|
if (proxy) {
|
|
343
354
|
const result$1 = await proxyFetch({
|
|
344
|
-
action: "auth:
|
|
355
|
+
action: "auth/session:start",
|
|
345
356
|
args: {
|
|
346
357
|
provider,
|
|
347
358
|
params
|
|
@@ -362,7 +373,7 @@ function client(options) {
|
|
|
362
373
|
};
|
|
363
374
|
if (result$1.deviceCode !== void 0) return {
|
|
364
375
|
signingIn: false,
|
|
365
|
-
deviceCode: result$1.deviceCode
|
|
376
|
+
deviceCode: normalizeDeviceCodeResult(result$1.deviceCode)
|
|
366
377
|
};
|
|
367
378
|
if (result$1.tokens !== void 0) return { signingIn: await setTokenAndMaybeWait({
|
|
368
379
|
shouldStore: false,
|
|
@@ -377,7 +388,7 @@ function client(options) {
|
|
|
377
388
|
}
|
|
378
389
|
const verifier = await storageGet(VERIFIER_STORAGE_KEY) ?? void 0;
|
|
379
390
|
await storageRemove(VERIFIER_STORAGE_KEY);
|
|
380
|
-
const result = await convex.action("auth:
|
|
391
|
+
const result = await convex.action("auth/session:start", {
|
|
381
392
|
provider,
|
|
382
393
|
params,
|
|
383
394
|
verifier
|
|
@@ -398,7 +409,7 @@ function client(options) {
|
|
|
398
409
|
};
|
|
399
410
|
if (result.deviceCode !== void 0) return {
|
|
400
411
|
signingIn: false,
|
|
401
|
-
deviceCode: result.deviceCode
|
|
412
|
+
deviceCode: normalizeDeviceCodeResult(result.deviceCode)
|
|
402
413
|
};
|
|
403
414
|
if (result.tokens !== void 0) return { signingIn: await setTokenAndMaybeWait({
|
|
404
415
|
shouldStore: true,
|
|
@@ -422,7 +433,7 @@ function client(options) {
|
|
|
422
433
|
if (proxy) {
|
|
423
434
|
try {
|
|
424
435
|
await proxyFetch({
|
|
425
|
-
action: "auth:
|
|
436
|
+
action: "auth/session:stop",
|
|
426
437
|
args: {}
|
|
427
438
|
});
|
|
428
439
|
} catch {}
|
|
@@ -434,7 +445,7 @@ function client(options) {
|
|
|
434
445
|
return;
|
|
435
446
|
}
|
|
436
447
|
try {
|
|
437
|
-
await convex.action("auth:
|
|
448
|
+
await convex.action("auth/session:stop", {});
|
|
438
449
|
} catch {}
|
|
439
450
|
await setToken({
|
|
440
451
|
shouldStore: true,
|
|
@@ -455,7 +466,7 @@ function client(options) {
|
|
|
455
466
|
if (token !== tokenBeforeRefresh) return token;
|
|
456
467
|
try {
|
|
457
468
|
const result = await proxyFetch({
|
|
458
|
-
action: "auth:
|
|
469
|
+
action: "auth/session:start",
|
|
459
470
|
args: { refreshToken: true }
|
|
460
471
|
});
|
|
461
472
|
if (result.tokens) await setToken({
|
|
@@ -498,7 +509,7 @@ function client(options) {
|
|
|
498
509
|
await signIn(void 0, { code });
|
|
499
510
|
const codeUrl = new URL(window.location.href);
|
|
500
511
|
codeUrl.searchParams.delete("code");
|
|
501
|
-
await
|
|
512
|
+
await replace_url(codeUrl.pathname + codeUrl.search + codeUrl.hash);
|
|
502
513
|
} finally {
|
|
503
514
|
handlingCodeFlow = false;
|
|
504
515
|
}
|
|
@@ -515,13 +526,13 @@ function client(options) {
|
|
|
515
526
|
* with the current state, then again on every state transition.
|
|
516
527
|
*
|
|
517
528
|
* ```ts
|
|
518
|
-
* const unsub = auth.
|
|
529
|
+
* const unsub = auth.on_change(setState);
|
|
519
530
|
* ```
|
|
520
531
|
*
|
|
521
532
|
* @param cb - Callback receiving the latest {@link AuthState}.
|
|
522
533
|
* @returns An unsubscribe function.
|
|
523
534
|
*/
|
|
524
|
-
const
|
|
535
|
+
const on_change = (cb) => {
|
|
525
536
|
cb(snapshot);
|
|
526
537
|
const wrapped = () => cb(snapshot);
|
|
527
538
|
subscribers.add(wrapped);
|
|
@@ -588,9 +599,9 @@ function client(options) {
|
|
|
588
599
|
get state() {
|
|
589
600
|
return snapshot;
|
|
590
601
|
},
|
|
591
|
-
signIn,
|
|
592
|
-
signOut,
|
|
593
|
-
|
|
602
|
+
sign_in: signIn,
|
|
603
|
+
sign_out: signOut,
|
|
604
|
+
on_change,
|
|
594
605
|
passkey: {
|
|
595
606
|
isSupported: () => {
|
|
596
607
|
return typeof window !== "undefined" && typeof window.PublicKeyCredential !== "undefined";
|
|
@@ -610,13 +621,13 @@ function client(options) {
|
|
|
610
621
|
};
|
|
611
622
|
let phase1Result;
|
|
612
623
|
if (proxy) phase1Result = await proxyFetch({
|
|
613
|
-
action: "auth:
|
|
624
|
+
action: "auth/session:start",
|
|
614
625
|
args: {
|
|
615
626
|
provider: "passkey",
|
|
616
627
|
params: phase1Params
|
|
617
628
|
}
|
|
618
629
|
});
|
|
619
|
-
else phase1Result = await convex.action("auth:
|
|
630
|
+
else phase1Result = await convex.action("auth/session:start", {
|
|
620
631
|
provider: "passkey",
|
|
621
632
|
params: phase1Params
|
|
622
633
|
});
|
|
@@ -654,14 +665,14 @@ function client(options) {
|
|
|
654
665
|
};
|
|
655
666
|
let phase2Result;
|
|
656
667
|
if (proxy) phase2Result = await proxyFetch({
|
|
657
|
-
action: "auth:
|
|
668
|
+
action: "auth/session:start",
|
|
658
669
|
args: {
|
|
659
670
|
provider: "passkey",
|
|
660
671
|
params: phase2Params,
|
|
661
672
|
verifier: phase1Result.verifier
|
|
662
673
|
}
|
|
663
674
|
});
|
|
664
|
-
else phase2Result = await convex.action("auth:
|
|
675
|
+
else phase2Result = await convex.action("auth/session:start", {
|
|
665
676
|
provider: "passkey",
|
|
666
677
|
params: phase2Params,
|
|
667
678
|
verifier: phase1Result.verifier
|
|
@@ -696,13 +707,13 @@ function client(options) {
|
|
|
696
707
|
};
|
|
697
708
|
let phase1Result;
|
|
698
709
|
if (proxy) phase1Result = await proxyFetch({
|
|
699
|
-
action: "auth:
|
|
710
|
+
action: "auth/session:start",
|
|
700
711
|
args: {
|
|
701
712
|
provider: "passkey",
|
|
702
713
|
params: phase1Params
|
|
703
714
|
}
|
|
704
715
|
});
|
|
705
|
-
else phase1Result = await convex.action("auth:
|
|
716
|
+
else phase1Result = await convex.action("auth/session:start", {
|
|
706
717
|
provider: "passkey",
|
|
707
718
|
params: phase1Params
|
|
708
719
|
});
|
|
@@ -734,14 +745,14 @@ function client(options) {
|
|
|
734
745
|
};
|
|
735
746
|
let phase2Result;
|
|
736
747
|
if (proxy) phase2Result = await proxyFetch({
|
|
737
|
-
action: "auth:
|
|
748
|
+
action: "auth/session:start",
|
|
738
749
|
args: {
|
|
739
750
|
provider: "passkey",
|
|
740
751
|
params: phase2Params,
|
|
741
752
|
verifier: phase1Result.verifier
|
|
742
753
|
}
|
|
743
754
|
});
|
|
744
|
-
else phase2Result = await convex.action("auth:
|
|
755
|
+
else phase2Result = await convex.action("auth/session:start", {
|
|
745
756
|
provider: "passkey",
|
|
746
757
|
params: phase2Params,
|
|
747
758
|
verifier: phase1Result.verifier
|
|
@@ -777,7 +788,7 @@ function client(options) {
|
|
|
777
788
|
if (opts?.accountName) params.accountName = opts.accountName;
|
|
778
789
|
if (proxy) {
|
|
779
790
|
const result$1 = await proxyFetch({
|
|
780
|
-
action: "auth:
|
|
791
|
+
action: "auth/session:start",
|
|
781
792
|
args: {
|
|
782
793
|
provider: "totp",
|
|
783
794
|
params
|
|
@@ -790,7 +801,7 @@ function client(options) {
|
|
|
790
801
|
totpId: result$1.totpSetup.totpId
|
|
791
802
|
};
|
|
792
803
|
}
|
|
793
|
-
const result = await convex.action("auth:
|
|
804
|
+
const result = await convex.action("auth/session:start", {
|
|
794
805
|
provider: "totp",
|
|
795
806
|
params
|
|
796
807
|
});
|
|
@@ -809,7 +820,7 @@ function client(options) {
|
|
|
809
820
|
};
|
|
810
821
|
if (proxy) {
|
|
811
822
|
const result$1 = await proxyFetch({
|
|
812
|
-
action: "auth:
|
|
823
|
+
action: "auth/session:start",
|
|
813
824
|
args: {
|
|
814
825
|
provider: "totp",
|
|
815
826
|
params,
|
|
@@ -827,7 +838,7 @@ function client(options) {
|
|
|
827
838
|
});
|
|
828
839
|
return;
|
|
829
840
|
}
|
|
830
|
-
const result = await convex.action("auth:
|
|
841
|
+
const result = await convex.action("auth/session:start", {
|
|
831
842
|
provider: "totp",
|
|
832
843
|
params,
|
|
833
844
|
verifier: opts.verifier
|
|
@@ -849,7 +860,7 @@ function client(options) {
|
|
|
849
860
|
};
|
|
850
861
|
if (proxy) {
|
|
851
862
|
const result$1 = await proxyFetch({
|
|
852
|
-
action: "auth:
|
|
863
|
+
action: "auth/session:start",
|
|
853
864
|
args: {
|
|
854
865
|
provider: "totp",
|
|
855
866
|
params,
|
|
@@ -867,7 +878,7 @@ function client(options) {
|
|
|
867
878
|
});
|
|
868
879
|
return;
|
|
869
880
|
}
|
|
870
|
-
const result = await convex.action("auth:
|
|
881
|
+
const result = await convex.action("auth/session:start", {
|
|
871
882
|
provider: "totp",
|
|
872
883
|
params,
|
|
873
884
|
verifier: opts.verifier
|
|
@@ -896,13 +907,13 @@ function client(options) {
|
|
|
896
907
|
deviceCode: code.deviceCode
|
|
897
908
|
};
|
|
898
909
|
if (proxy) result = await proxyFetch({
|
|
899
|
-
action: "auth:
|
|
910
|
+
action: "auth/session:start",
|
|
900
911
|
args: {
|
|
901
912
|
provider: "device",
|
|
902
913
|
params
|
|
903
914
|
}
|
|
904
915
|
});
|
|
905
|
-
else result = await convex.action("auth:
|
|
916
|
+
else result = await convex.action("auth/session:start", {
|
|
906
917
|
provider: "device",
|
|
907
918
|
params
|
|
908
919
|
});
|
|
@@ -947,13 +958,13 @@ function client(options) {
|
|
|
947
958
|
userCode
|
|
948
959
|
};
|
|
949
960
|
if (proxy) await proxyFetch({
|
|
950
|
-
action: "auth:
|
|
961
|
+
action: "auth/session:start",
|
|
951
962
|
args: {
|
|
952
963
|
provider: "device",
|
|
953
964
|
params
|
|
954
965
|
}
|
|
955
966
|
});
|
|
956
|
-
else await convex.action("auth:
|
|
967
|
+
else await convex.action("auth/session:start", {
|
|
957
968
|
provider: "device",
|
|
958
969
|
params
|
|
959
970
|
});
|