@robelest/convex-auth 0.0.4-preview.21 → 0.0.4-preview.23
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/authorization/index.d.ts +1 -1
- package/dist/authorization/index.js +1 -1
- package/dist/authorization/index.js.map +1 -1
- package/dist/client/index.d.ts +1 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +36 -39
- package/dist/client/index.js.map +1 -1
- package/dist/component/client/index.d.ts +1 -2
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/convex.config.d.ts.map +1 -1
- package/dist/component/model.d.ts +5 -5
- package/dist/component/model.d.ts.map +1 -1
- package/dist/component/public/enterprise/audit.d.ts.map +1 -1
- package/dist/component/public/enterprise/audit.js.map +1 -1
- package/dist/component/public/enterprise/core.d.ts.map +1 -1
- package/dist/component/public/enterprise/core.js.map +1 -1
- package/dist/component/public/enterprise/domains.d.ts.map +1 -1
- package/dist/component/public/enterprise/domains.js.map +1 -1
- package/dist/component/public/enterprise/scim.d.ts.map +1 -1
- package/dist/component/public/enterprise/scim.js.map +1 -1
- package/dist/component/public/enterprise/secrets.d.ts.map +1 -1
- package/dist/component/public/enterprise/secrets.js.map +1 -1
- package/dist/component/public/enterprise/webhooks.d.ts.map +1 -1
- package/dist/component/public/enterprise/webhooks.js.map +1 -1
- package/dist/component/public/factors/devices.d.ts.map +1 -1
- package/dist/component/public/factors/devices.js.map +1 -1
- package/dist/component/public/factors/passkeys.d.ts.map +1 -1
- package/dist/component/public/factors/passkeys.js.map +1 -1
- package/dist/component/public/factors/totp.d.ts.map +1 -1
- package/dist/component/public/factors/totp.js.map +1 -1
- package/dist/component/public/groups/core.js.map +1 -1
- package/dist/component/public/groups/invites.d.ts.map +1 -1
- package/dist/component/public/groups/invites.js.map +1 -1
- package/dist/component/public/groups/members.d.ts.map +1 -1
- package/dist/component/public/groups/members.js.map +1 -1
- package/dist/component/public/identity/accounts.d.ts.map +1 -1
- package/dist/component/public/identity/accounts.js.map +1 -1
- package/dist/component/public/identity/codes.d.ts.map +1 -1
- package/dist/component/public/identity/codes.js.map +1 -1
- package/dist/component/public/identity/sessions.d.ts.map +1 -1
- package/dist/component/public/identity/sessions.js.map +1 -1
- package/dist/component/public/identity/tokens.d.ts.map +1 -1
- package/dist/component/public/identity/tokens.js.map +1 -1
- package/dist/component/public/identity/users.d.ts.map +1 -1
- package/dist/component/public/identity/users.js.map +1 -1
- package/dist/component/public/identity/verifiers.d.ts.map +1 -1
- package/dist/component/public/identity/verifiers.js.map +1 -1
- package/dist/component/public/security/keys.d.ts.map +1 -1
- package/dist/component/public/security/keys.js.map +1 -1
- package/dist/component/public/security/limits.d.ts.map +1 -1
- package/dist/component/public/security/limits.js.map +1 -1
- package/dist/component/schema.d.ts +39 -39
- package/dist/component/server/auth.d.ts +95 -52
- package/dist/component/server/auth.d.ts.map +1 -1
- package/dist/component/server/auth.js +63 -43
- package/dist/component/server/auth.js.map +1 -1
- package/dist/component/server/core.js +116 -235
- package/dist/component/server/core.js.map +1 -1
- package/dist/component/server/crypto.js +25 -7
- package/dist/component/server/crypto.js.map +1 -1
- package/dist/component/server/device.js +58 -15
- package/dist/component/server/device.js.map +1 -1
- package/dist/component/server/enterprise/domain.js +148 -59
- package/dist/component/server/enterprise/domain.js.map +1 -1
- package/dist/component/server/enterprise/http.js +36 -15
- package/dist/component/server/enterprise/http.js.map +1 -1
- package/dist/component/server/enterprise/oidc.js +1 -1
- package/dist/component/server/http.js +26 -21
- package/dist/component/server/http.js.map +1 -1
- package/dist/component/server/identity.js +5 -2
- package/dist/component/server/identity.js.map +1 -1
- package/dist/component/server/limits.js +21 -30
- package/dist/component/server/limits.js.map +1 -1
- package/dist/component/server/mutations/account.js +12 -10
- package/dist/component/server/mutations/account.js.map +1 -1
- package/dist/component/server/mutations/code.js +5 -2
- package/dist/component/server/mutations/code.js.map +1 -1
- package/dist/component/server/mutations/invalidate.js +1 -1
- package/dist/component/server/mutations/invalidate.js.map +1 -1
- package/dist/component/server/mutations/oauth.js +10 -4
- package/dist/component/server/mutations/oauth.js.map +1 -1
- package/dist/component/server/mutations/refresh.js +2 -2
- package/dist/component/server/mutations/refresh.js.map +1 -1
- package/dist/component/server/mutations/register.js +46 -42
- package/dist/component/server/mutations/register.js.map +1 -1
- package/dist/component/server/mutations/retrieve.js +21 -25
- package/dist/component/server/mutations/retrieve.js.map +1 -1
- package/dist/component/server/mutations/signature.js +10 -4
- package/dist/component/server/mutations/signature.js.map +1 -1
- package/dist/component/server/mutations/signout.js.map +1 -1
- package/dist/component/server/mutations/store.js +9 -24
- package/dist/component/server/mutations/store.js.map +1 -1
- package/dist/component/server/mutations/verifier.js.map +1 -1
- package/dist/component/server/mutations/verify.js +1 -1
- package/dist/component/server/mutations/verify.js.map +1 -1
- package/dist/component/server/oauth.js +53 -16
- package/dist/component/server/oauth.js.map +1 -1
- package/dist/component/server/passkey.js +115 -31
- package/dist/component/server/passkey.js.map +1 -1
- package/dist/component/server/redirects.js +9 -3
- package/dist/component/server/redirects.js.map +1 -1
- package/dist/component/server/refresh.js +10 -7
- package/dist/component/server/refresh.js.map +1 -1
- package/dist/component/server/runtime.d.ts +3 -3
- package/dist/component/server/runtime.d.ts.map +1 -1
- package/dist/component/server/runtime.js +62 -20
- package/dist/component/server/runtime.js.map +1 -1
- package/dist/component/server/signin.js +34 -10
- package/dist/component/server/signin.js.map +1 -1
- package/dist/component/server/totp.js +79 -19
- package/dist/component/server/totp.js.map +1 -1
- package/dist/component/server/types.d.ts +12 -20
- package/dist/component/server/types.d.ts.map +1 -1
- package/dist/component/server/types.js.map +1 -1
- package/dist/component/server/users.js +6 -3
- package/dist/component/server/users.js.map +1 -1
- package/dist/component/server/utils.js +10 -4
- package/dist/component/server/utils.js.map +1 -1
- package/dist/core/types.d.ts +14 -22
- package/dist/core/types.d.ts.map +1 -1
- package/dist/factors/device.js +8 -9
- package/dist/factors/device.js.map +1 -1
- package/dist/factors/passkey.js +18 -21
- package/dist/factors/passkey.js.map +1 -1
- package/dist/providers/password.js +66 -81
- package/dist/providers/password.js.map +1 -1
- package/dist/runtime/invite.js +2 -8
- package/dist/runtime/invite.js.map +1 -1
- package/dist/server/auth.d.ts +95 -52
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +63 -43
- package/dist/server/auth.js.map +1 -1
- package/dist/server/core.d.ts +71 -159
- package/dist/server/core.d.ts.map +1 -1
- package/dist/server/core.js +116 -235
- package/dist/server/core.js.map +1 -1
- package/dist/server/crypto.d.ts.map +1 -1
- package/dist/server/crypto.js +25 -7
- package/dist/server/crypto.js.map +1 -1
- package/dist/server/device.js +58 -15
- package/dist/server/device.js.map +1 -1
- package/dist/server/enterprise/domain.d.ts +0 -8
- package/dist/server/enterprise/domain.d.ts.map +1 -1
- package/dist/server/enterprise/domain.js +148 -59
- package/dist/server/enterprise/domain.js.map +1 -1
- package/dist/server/enterprise/http.d.ts.map +1 -1
- package/dist/server/enterprise/http.js +35 -14
- package/dist/server/enterprise/http.js.map +1 -1
- package/dist/server/http.d.ts +2 -2
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js +25 -20
- package/dist/server/http.js.map +1 -1
- package/dist/server/identity.js +5 -2
- package/dist/server/identity.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/limits.js +21 -30
- package/dist/server/limits.js.map +1 -1
- package/dist/server/mounts.d.ts +26 -64
- package/dist/server/mounts.d.ts.map +1 -1
- package/dist/server/mounts.js +45 -106
- package/dist/server/mounts.js.map +1 -1
- package/dist/server/mutations/account.d.ts +8 -9
- package/dist/server/mutations/account.d.ts.map +1 -1
- package/dist/server/mutations/account.js +11 -9
- package/dist/server/mutations/account.js.map +1 -1
- package/dist/server/mutations/code.d.ts +13 -13
- package/dist/server/mutations/code.d.ts.map +1 -1
- package/dist/server/mutations/code.js +5 -2
- package/dist/server/mutations/code.js.map +1 -1
- package/dist/server/mutations/invalidate.d.ts +4 -4
- package/dist/server/mutations/invalidate.d.ts.map +1 -1
- package/dist/server/mutations/invalidate.js.map +1 -1
- package/dist/server/mutations/oauth.d.ts +12 -10
- package/dist/server/mutations/oauth.d.ts.map +1 -1
- package/dist/server/mutations/oauth.js +9 -3
- package/dist/server/mutations/oauth.js.map +1 -1
- package/dist/server/mutations/refresh.d.ts +3 -3
- package/dist/server/mutations/refresh.d.ts.map +1 -1
- package/dist/server/mutations/refresh.js +1 -1
- package/dist/server/mutations/refresh.js.map +1 -1
- package/dist/server/mutations/register.d.ts +11 -11
- package/dist/server/mutations/register.d.ts.map +1 -1
- package/dist/server/mutations/register.js +45 -41
- package/dist/server/mutations/register.js.map +1 -1
- package/dist/server/mutations/retrieve.d.ts +6 -6
- package/dist/server/mutations/retrieve.d.ts.map +1 -1
- package/dist/server/mutations/retrieve.js +20 -24
- package/dist/server/mutations/retrieve.js.map +1 -1
- package/dist/server/mutations/signature.d.ts +6 -7
- package/dist/server/mutations/signature.d.ts.map +1 -1
- package/dist/server/mutations/signature.js +9 -3
- package/dist/server/mutations/signature.js.map +1 -1
- package/dist/server/mutations/signin.d.ts +5 -5
- package/dist/server/mutations/signin.d.ts.map +1 -1
- package/dist/server/mutations/signout.js.map +1 -1
- package/dist/server/mutations/store.d.ts +97 -97
- package/dist/server/mutations/store.d.ts.map +1 -1
- package/dist/server/mutations/store.js +8 -23
- package/dist/server/mutations/store.js.map +1 -1
- package/dist/server/mutations/verifier.js.map +1 -1
- package/dist/server/mutations/verify.d.ts +10 -10
- package/dist/server/mutations/verify.d.ts.map +1 -1
- package/dist/server/mutations/verify.js.map +1 -1
- package/dist/server/oauth.js +53 -16
- package/dist/server/oauth.js.map +1 -1
- package/dist/server/passkey.d.ts +2 -2
- package/dist/server/passkey.d.ts.map +1 -1
- package/dist/server/passkey.js +114 -30
- package/dist/server/passkey.js.map +1 -1
- package/dist/server/redirects.js +9 -3
- package/dist/server/redirects.js.map +1 -1
- package/dist/server/refresh.js +10 -7
- package/dist/server/refresh.js.map +1 -1
- package/dist/server/runtime.d.ts +14 -14
- package/dist/server/runtime.d.ts.map +1 -1
- package/dist/server/runtime.js +61 -19
- package/dist/server/runtime.js.map +1 -1
- package/dist/server/signin.js +34 -10
- package/dist/server/signin.js.map +1 -1
- package/dist/server/ssr.d.ts.map +1 -1
- package/dist/server/ssr.js +175 -184
- package/dist/server/ssr.js.map +1 -1
- package/dist/server/totp.js +78 -18
- package/dist/server/totp.js.map +1 -1
- package/dist/server/types.d.ts +13 -21
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js.map +1 -1
- package/dist/server/users.js +6 -3
- package/dist/server/users.js.map +1 -1
- package/dist/server/utils.js +10 -4
- package/dist/server/utils.js.map +1 -1
- package/package.json +2 -6
- package/src/authorization/index.ts +1 -1
- package/src/cli/index.ts +1 -1
- package/src/client/core/types.ts +14 -14
- package/src/client/factors/device.ts +10 -12
- package/src/client/factors/passkey.ts +23 -26
- package/src/client/index.ts +54 -64
- package/src/client/runtime/invite.ts +5 -7
- package/src/component/index.ts +1 -0
- package/src/component/public/enterprise/audit.ts +6 -1
- package/src/component/public/enterprise/core.ts +1 -0
- package/src/component/public/enterprise/domains.ts +5 -1
- package/src/component/public/enterprise/scim.ts +1 -0
- package/src/component/public/enterprise/secrets.ts +1 -0
- package/src/component/public/enterprise/webhooks.ts +1 -0
- package/src/component/public/factors/devices.ts +1 -0
- package/src/component/public/factors/passkeys.ts +1 -0
- package/src/component/public/factors/totp.ts +1 -0
- package/src/component/public/groups/core.ts +1 -1
- package/src/component/public/groups/invites.ts +7 -1
- package/src/component/public/groups/members.ts +1 -0
- package/src/component/public/identity/accounts.ts +1 -0
- package/src/component/public/identity/codes.ts +1 -0
- package/src/component/public/identity/sessions.ts +1 -0
- package/src/component/public/identity/tokens.ts +1 -0
- package/src/component/public/identity/users.ts +1 -0
- package/src/component/public/identity/verifiers.ts +1 -0
- package/src/component/public/security/keys.ts +1 -0
- package/src/component/public/security/limits.ts +1 -0
- package/src/providers/password.ts +89 -110
- package/src/server/auth.ts +177 -111
- package/src/server/core.ts +197 -233
- package/src/server/crypto.ts +31 -29
- package/src/server/device.ts +65 -32
- package/src/server/enterprise/domain.ts +158 -170
- package/src/server/enterprise/http.ts +46 -39
- package/src/server/http.ts +36 -30
- package/src/server/identity.ts +5 -5
- package/src/server/index.ts +2 -0
- package/src/server/limits.ts +53 -80
- package/src/server/mounts.ts +47 -74
- package/src/server/mutations/account.ts +22 -36
- package/src/server/mutations/code.ts +6 -6
- package/src/server/mutations/invalidate.ts +1 -1
- package/src/server/mutations/oauth.ts +14 -8
- package/src/server/mutations/refresh.ts +5 -4
- package/src/server/mutations/register.ts +87 -132
- package/src/server/mutations/retrieve.ts +44 -44
- package/src/server/mutations/signature.ts +13 -6
- package/src/server/mutations/signout.ts +1 -1
- package/src/server/mutations/store.ts +16 -31
- package/src/server/mutations/verifier.ts +1 -1
- package/src/server/mutations/verify.ts +3 -5
- package/src/server/oauth.ts +60 -69
- package/src/server/passkey.ts +567 -517
- package/src/server/redirects.ts +10 -6
- package/src/server/refresh.ts +14 -18
- package/src/server/runtime.ts +70 -55
- package/src/server/signin.ts +44 -37
- package/src/server/ssr.ts +390 -407
- package/src/server/totp.ts +85 -35
- package/src/server/types.ts +19 -22
- package/src/server/users.ts +7 -6
- package/src/server/utils.ts +10 -12
- package/dist/component/server/authError.js +0 -34
- package/dist/component/server/authError.js.map +0 -1
- package/dist/component/server/errors.d.ts +0 -1
- package/dist/component/server/errors.js +0 -137
- package/dist/component/server/errors.js.map +0 -1
- package/dist/server/authError.d.ts +0 -46
- package/dist/server/authError.d.ts.map +0 -1
- package/dist/server/authError.js +0 -34
- package/dist/server/authError.js.map +0 -1
- package/dist/server/errors.d.ts +0 -177
- package/dist/server/errors.d.ts.map +0 -1
- package/dist/server/errors.js +0 -212
- package/dist/server/errors.js.map +0 -1
- package/src/server/authError.ts +0 -44
- package/src/server/errors.ts +0 -290
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { AuthErrorCode } from "./errors.js";
|
|
2
|
-
import { ConvexError } from "convex/values";
|
|
3
|
-
|
|
4
|
-
//#region src/server/authError.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Typed error for the Fx error channel.
|
|
7
|
-
*
|
|
8
|
-
* Use with `Fx.fail(new AuthError("CODE"))` in pipelines.
|
|
9
|
-
* At Convex boundaries, {@link toConvexError} converts these to `ConvexError`.
|
|
10
|
-
*/
|
|
11
|
-
declare class AuthError extends Error {
|
|
12
|
-
/**
|
|
13
|
-
* Machine-readable error code.
|
|
14
|
-
* @readonly
|
|
15
|
-
*/
|
|
16
|
-
readonly code: AuthErrorCode;
|
|
17
|
-
/**
|
|
18
|
-
* Optional structured context for diagnostics.
|
|
19
|
-
* @readonly
|
|
20
|
-
*/
|
|
21
|
-
readonly context?: Record<string, unknown> | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Discriminant tag for error channel matching.
|
|
24
|
-
* @readonly
|
|
25
|
-
*/
|
|
26
|
-
readonly _tag: "AuthError";
|
|
27
|
-
constructor(
|
|
28
|
-
/**
|
|
29
|
-
* Machine-readable error code.
|
|
30
|
-
* @readonly
|
|
31
|
-
*/
|
|
32
|
-
code: AuthErrorCode, message?: string,
|
|
33
|
-
/**
|
|
34
|
-
* Optional structured context for diagnostics.
|
|
35
|
-
* @readonly
|
|
36
|
-
*/
|
|
37
|
-
context?: Record<string, unknown> | undefined);
|
|
38
|
-
/** Convert to the `ConvexError` shape the Convex runtime expects. */
|
|
39
|
-
toConvexError(): ConvexError<{
|
|
40
|
-
code: AuthErrorCode;
|
|
41
|
-
message: string;
|
|
42
|
-
}>;
|
|
43
|
-
}
|
|
44
|
-
//#endregion
|
|
45
|
-
export { AuthError };
|
|
46
|
-
//# sourceMappingURL=authError.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authError.d.ts","names":[],"sources":["../../src/server/authError.ts"],"mappings":";;;;;;AAYA;;;;cAAa,SAAA,SAAkB,KAAA;EAYZ;;;;EAAA,SAAN,IAAA,EAAM,aAAA;EAZiB;;;;EAAA,SAkBvB,OAAA,GAAU,MAAA;EAAV;;;;EAAA,SAbF,IAAA;;EAQP;;;;EADS,IAAA,EAAM,aAAA,EACf,OAAA;EAW6B;;;;EANpB,OAAA,GAAU,MAAA;;EAMrB,aAAA,CAAA,GAAiB,WAAA;IAAc,IAAA,EAAM,aAAA;IAAe,OAAA;EAAA;AAAA"}
|
package/dist/server/authError.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { AUTH_ERRORS } from "./errors.js";
|
|
2
|
-
import { Cv } from "@robelest/fx/convex";
|
|
3
|
-
|
|
4
|
-
//#region src/server/authError.ts
|
|
5
|
-
/**
|
|
6
|
-
* Typed error for the Fx error channel.
|
|
7
|
-
*
|
|
8
|
-
* Use with `Fx.fail(new AuthError("CODE"))` in pipelines.
|
|
9
|
-
* At Convex boundaries, {@link toConvexError} converts these to `ConvexError`.
|
|
10
|
-
*/
|
|
11
|
-
var AuthError = class extends Error {
|
|
12
|
-
/**
|
|
13
|
-
* Discriminant tag for error channel matching.
|
|
14
|
-
* @readonly
|
|
15
|
-
*/
|
|
16
|
-
_tag = "AuthError";
|
|
17
|
-
constructor(code, message, context) {
|
|
18
|
-
super(message ?? AUTH_ERRORS[code]);
|
|
19
|
-
this.code = code;
|
|
20
|
-
this.context = context;
|
|
21
|
-
}
|
|
22
|
-
/** Convert to the `ConvexError` shape the Convex runtime expects. */
|
|
23
|
-
toConvexError() {
|
|
24
|
-
return Cv.error({
|
|
25
|
-
code: this.code,
|
|
26
|
-
message: this.message,
|
|
27
|
-
...this.context
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
export { AuthError };
|
|
34
|
-
//# sourceMappingURL=authError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authError.js","names":[],"sources":["../../src/server/authError.ts"],"sourcesContent":["import { Cv } from \"@robelest/fx/convex\";\nimport type { ConvexError } from \"convex/values\";\n\nimport { AUTH_ERRORS } from \"./errors\";\nimport type { AuthErrorCode } from \"./errors\";\n\n/**\n * Typed error for the Fx error channel.\n *\n * Use with `Fx.fail(new AuthError(\"CODE\"))` in pipelines.\n * At Convex boundaries, {@link toConvexError} converts these to `ConvexError`.\n */\nexport class AuthError extends Error {\n /**\n * Discriminant tag for error channel matching.\n * @readonly\n */\n readonly _tag = \"AuthError\" as const;\n\n constructor(\n /**\n * Machine-readable error code.\n * @readonly\n */\n readonly code: AuthErrorCode,\n message?: string,\n /**\n * Optional structured context for diagnostics.\n * @readonly\n */\n readonly context?: Record<string, unknown>,\n ) {\n super(message ?? AUTH_ERRORS[code]);\n }\n\n /** Convert to the `ConvexError` shape the Convex runtime expects. */\n toConvexError(): ConvexError<{ code: AuthErrorCode; message: string }> {\n return Cv.error({\n code: this.code,\n message: this.message,\n ...this.context,\n });\n }\n}\n"],"mappings":";;;;;;;;;;AAYA,IAAa,YAAb,cAA+B,MAAM;;;;;CAKnC,AAAS,OAAO;CAEhB,YAKE,AAAS,MACT,SAKA,AAAS,SACT;AACA,QAAM,WAAW,YAAY,MAAM;EAR1B;EAMA;;;CAMX,gBAAuE;AACrE,SAAO,GAAG,MAAM;GACd,MAAM,KAAK;GACX,SAAS,KAAK;GACd,GAAG,KAAK;GACT,CAAC"}
|
package/dist/server/errors.d.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { ConvexError } from "convex/values";
|
|
2
|
-
|
|
3
|
-
//#region src/server/errors.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Map of every auth error code to its default human-readable message.
|
|
6
|
-
*
|
|
7
|
-
* Use the keys as the `code` argument to {@link throwAuthError}.
|
|
8
|
-
* Clients can match on these codes for conditional error handling.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* throwAuthError("NOT_SIGNED_IN");
|
|
13
|
-
* // ConvexError { data: { code: "NOT_SIGNED_IN", message: "You must be signed in..." } }
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
declare const AUTH_ERRORS: {
|
|
17
|
-
readonly PROVIDER_NOT_CONFIGURED: "This sign-in method is not available.";
|
|
18
|
-
readonly EMAIL_CONFIG_REQUIRED: "Email transport is not configured. Configure email in createAuth(...).";
|
|
19
|
-
readonly MISSING_ENV_VAR: "A required server environment variable is missing.";
|
|
20
|
-
readonly MISSING_ACTION_CONTEXT: "Action context is required for this operation.";
|
|
21
|
-
readonly INVALID_PARAMETERS: "The provided parameters are invalid.";
|
|
22
|
-
readonly NOT_SIGNED_IN: "You must be signed in to perform this action.";
|
|
23
|
-
readonly INVALID_VERIFICATION_CODE: "Invalid or expired verification code.";
|
|
24
|
-
readonly INVALID_REFRESH_TOKEN: "Your session has expired. Please sign in again.";
|
|
25
|
-
readonly AUTH_HANDSHAKE_TIMEOUT: "Sign-in succeeded but authentication confirmation timed out.";
|
|
26
|
-
readonly AUTH_HANDSHAKE_REJECTED: "Authentication was rejected while confirming the session.";
|
|
27
|
-
readonly SIGN_IN_MISSING_PARAMS: "Cannot sign in: missing provider, code, or refresh token.";
|
|
28
|
-
readonly UNSUPPORTED_PROVIDER_TYPE: "This provider type is not supported.";
|
|
29
|
-
readonly INVALID_REDIRECT: "Invalid redirect URL.";
|
|
30
|
-
readonly EMAIL_SEND_FAILED: "Failed to send verification email. Please try again.";
|
|
31
|
-
readonly INVALID_API_KEY: "Invalid API key.";
|
|
32
|
-
readonly API_KEY_REVOKED: "This API key has been revoked.";
|
|
33
|
-
readonly API_KEY_EXPIRED: "This API key has expired.";
|
|
34
|
-
readonly API_KEY_RATE_LIMITED: "API key rate limit exceeded. Please try again later.";
|
|
35
|
-
readonly API_KEY_INVALID_SCOPE: "Invalid scope requested for API key.";
|
|
36
|
-
readonly KEY_NOT_FOUND: "API key not found.";
|
|
37
|
-
readonly MISSING_BEARER_TOKEN: "Missing or malformed Authorization: Bearer header.";
|
|
38
|
-
readonly SCOPE_CHECK_FAILED: "This API key does not have the required permissions.";
|
|
39
|
-
readonly OAUTH_MISSING_PROVIDER: "Missing OAuth provider ID.";
|
|
40
|
-
readonly OAUTH_MISSING_VERIFIER: "Missing sign-in verifier.";
|
|
41
|
-
readonly OAUTH_INVALID_STATE: "Invalid OAuth state. Please try signing in again.";
|
|
42
|
-
readonly OAUTH_PROVIDER_ERROR: "The sign-in provider returned an error.";
|
|
43
|
-
readonly OAUTH_MISSING_ID_TOKEN: "ID token claims are missing from the provider response.";
|
|
44
|
-
readonly OAUTH_INVALID_PROFILE: "The sign-in provider returned an invalid profile.";
|
|
45
|
-
readonly OAUTH_UNSUPPORTED_AUTH_METHOD: "Unsupported OAuth client authentication method.";
|
|
46
|
-
readonly OAUTH_NO_USERINFO: "No userinfo endpoint configured for this provider.";
|
|
47
|
-
readonly ACCOUNT_ALREADY_EXISTS: "An account with these credentials already exists.";
|
|
48
|
-
readonly ACCOUNT_NOT_FOUND: "Account not found.";
|
|
49
|
-
readonly INVALID_CREDENTIALS_PROVIDER: "This provider does not support credential operations.";
|
|
50
|
-
readonly MISSING_CRYPTO_FUNCTION: "This provider is missing a required cryptographic function.";
|
|
51
|
-
readonly USER_UPDATE_FAILED: "Could not update the user record.";
|
|
52
|
-
readonly INVALID_VERIFIER: "Invalid or expired verifier.";
|
|
53
|
-
readonly PASSKEY_MISSING_CONFIG: "Passkey provider requires SITE_URL or explicit rpId configuration.";
|
|
54
|
-
readonly PASSKEY_AUTH_REQUIRED: "Sign in first, then add a passkey to your account.";
|
|
55
|
-
readonly PASSKEY_MISSING_VERIFIER: "Missing verifier for passkey operation.";
|
|
56
|
-
readonly PASSKEY_INVALID_CLIENT_DATA: "Invalid passkey client data.";
|
|
57
|
-
readonly PASSKEY_INVALID_ORIGIN: "Passkey origin does not match the expected value.";
|
|
58
|
-
readonly PASSKEY_INVALID_CHALLENGE: "Invalid or expired passkey challenge.";
|
|
59
|
-
readonly PASSKEY_RP_MISMATCH: "Relying party ID mismatch.";
|
|
60
|
-
readonly PASSKEY_USER_PRESENCE: "User presence flag not set.";
|
|
61
|
-
readonly PASSKEY_USER_VERIFICATION: "User verification required but not performed.";
|
|
62
|
-
readonly PASSKEY_NO_CREDENTIAL: "No credential in attestation.";
|
|
63
|
-
readonly PASSKEY_UNSUPPORTED_ALGORITHM: "Unsupported passkey algorithm.";
|
|
64
|
-
readonly PASSKEY_INVALID_SIGNATURE: "Invalid passkey signature.";
|
|
65
|
-
readonly PASSKEY_UNKNOWN_CREDENTIAL: "Unknown passkey credential.";
|
|
66
|
-
readonly PASSKEY_COUNTER_ERROR: "Authenticator counter did not increase — possible credential cloning detected.";
|
|
67
|
-
readonly PASSKEY_MISSING_FLOW: "Missing passkey flow parameter.";
|
|
68
|
-
readonly PASSKEY_UNKNOWN_FLOW: "Unknown passkey flow.";
|
|
69
|
-
readonly TOTP_AUTH_REQUIRED: "Sign in first, then set up two-factor authentication.";
|
|
70
|
-
readonly TOTP_MISSING_VERIFIER: "Missing verifier for TOTP operation.";
|
|
71
|
-
readonly TOTP_MISSING_CODE: "Missing TOTP code.";
|
|
72
|
-
readonly TOTP_MISSING_ID: "Missing TOTP enrollment ID.";
|
|
73
|
-
readonly TOTP_NOT_FOUND: "TOTP enrollment not found.";
|
|
74
|
-
readonly TOTP_ALREADY_VERIFIED: "TOTP enrollment is already verified.";
|
|
75
|
-
readonly TOTP_INVALID_CODE: "Invalid TOTP code.";
|
|
76
|
-
readonly TOTP_INVALID_VERIFIER: "Invalid or expired TOTP verifier.";
|
|
77
|
-
readonly TOTP_NO_ENROLLMENT: "No verified TOTP enrollment found.";
|
|
78
|
-
readonly TOTP_MISSING_FLOW: "Missing TOTP flow parameter.";
|
|
79
|
-
readonly TOTP_UNKNOWN_FLOW: "Unknown TOTP flow.";
|
|
80
|
-
readonly DEVICE_CODE_EXPIRED: "The device code has expired. Please start a new authorization request.";
|
|
81
|
-
readonly DEVICE_CODE_DENIED: "The authorization request was denied.";
|
|
82
|
-
readonly DEVICE_AUTHORIZATION_PENDING: "The user has not yet authorized this device.";
|
|
83
|
-
readonly DEVICE_SLOW_DOWN: "Polling too frequently. Increase the interval between requests.";
|
|
84
|
-
readonly DEVICE_INVALID_USER_CODE: "Invalid or expired user code.";
|
|
85
|
-
readonly DEVICE_ALREADY_AUTHORIZED: "This device code has already been authorized.";
|
|
86
|
-
readonly DEVICE_MISSING_FLOW: "Missing device flow parameter.";
|
|
87
|
-
readonly DEVICE_UNKNOWN_FLOW: "Unknown device flow.";
|
|
88
|
-
readonly INVITE_EXPIRED: "This invitation has expired.";
|
|
89
|
-
readonly INVITE_EMAIL_MISMATCH: "This invitation is for a different email.";
|
|
90
|
-
readonly INVITE_ALREADY_ACCEPTED: "This invitation has already been accepted.";
|
|
91
|
-
readonly DUPLICATE_INVITE: "A pending invite already exists for this email in this group.";
|
|
92
|
-
readonly INVITE_NOT_FOUND: "Invite not found.";
|
|
93
|
-
readonly INVITE_NOT_PENDING: "Cannot accept or revoke invite that is not pending.";
|
|
94
|
-
readonly FORBIDDEN: "Access denied.";
|
|
95
|
-
readonly NO_ACTIVE_GROUP: "User has no active group set.";
|
|
96
|
-
readonly DUPLICATE_MEMBERSHIP: "User is already a member of this group.";
|
|
97
|
-
readonly ENTERPRISE_ALREADY_EXISTS: "An enterprise record already exists for this group.";
|
|
98
|
-
readonly ENTERPRISE_DOMAIN_TAKEN: "That domain is already attached to another enterprise.";
|
|
99
|
-
readonly INTERNAL_ERROR: "An unexpected error occurred.";
|
|
100
|
-
};
|
|
101
|
-
/** Union of all recognized auth error code strings (keys of {@link AUTH_ERRORS}). */
|
|
102
|
-
type AuthErrorCode = keyof typeof AUTH_ERRORS;
|
|
103
|
-
/**
|
|
104
|
-
* Throw a structured `ConvexError` with `{ code, message }`.
|
|
105
|
-
*
|
|
106
|
-
* Use this in your own Convex functions (queries, mutations, actions)
|
|
107
|
-
* to throw auth-domain errors that clients can match on by `code`.
|
|
108
|
-
* The library itself uses `AuthError` internally, but consumers
|
|
109
|
-
* should prefer this helper for simplicity.
|
|
110
|
-
*
|
|
111
|
-
* @param code Machine-readable error code from `AUTH_ERRORS`.
|
|
112
|
-
* @param message Optional override for the default human-readable message.
|
|
113
|
-
* @param context Optional extra fields merged into the error payload.
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* import { throwAuthError } from "@robelest/convex-auth/server";
|
|
118
|
-
*
|
|
119
|
-
* // In a custom mutation:
|
|
120
|
-
* if (!isAdmin) {
|
|
121
|
-
* throwAuthError("FORBIDDEN");
|
|
122
|
-
* }
|
|
123
|
-
* ```
|
|
124
|
-
*
|
|
125
|
-
* @throws {ConvexError} Always — throws a `ConvexError` with `{ code, message }` payload.
|
|
126
|
-
*/
|
|
127
|
-
declare function throwAuthError(code: AuthErrorCode, message?: string, context?: Record<string, unknown>): never;
|
|
128
|
-
/**
|
|
129
|
-
* Type guard: check whether a caught value is a structured auth `ConvexError`.
|
|
130
|
-
*
|
|
131
|
-
* @param error - The caught value (typically from a `catch` block).
|
|
132
|
-
* @returns `true` when `error` is a `ConvexError` with `{ code, message }` data.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```ts
|
|
136
|
-
* try { await auth.signIn('email', { email }); }
|
|
137
|
-
* catch (e) {
|
|
138
|
-
* if (isAuthError(e)) console.log(e.data.code); // "EMAIL_SEND_FAILED"
|
|
139
|
-
* }
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
declare function isAuthError(error: unknown): error is ConvexError<{
|
|
143
|
-
code: AuthErrorCode;
|
|
144
|
-
message: string;
|
|
145
|
-
}>;
|
|
146
|
-
/**
|
|
147
|
-
* Extract `{ code, message }` from a caught error.
|
|
148
|
-
*
|
|
149
|
-
* Works for `ConvexError` (from Convex actions), plain `Error`
|
|
150
|
-
* instances, and structured auth errors. Returns `null` when the
|
|
151
|
-
* value is not an error object.
|
|
152
|
-
*
|
|
153
|
-
* @param error - The caught value to parse.
|
|
154
|
-
* @returns `{ code, message }` when extractable, or `null`.
|
|
155
|
-
* When `code` is `null`, the error is not a structured auth error
|
|
156
|
-
* but `message` still contains the error text.
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* try {
|
|
161
|
-
* await auth.signIn("email", { email });
|
|
162
|
-
* } catch (e) {
|
|
163
|
-
* const err = parseAuthError(e);
|
|
164
|
-
* if (err?.code === "EMAIL_SEND_FAILED") { ... }
|
|
165
|
-
* }
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
declare function parseAuthError(error: unknown): {
|
|
169
|
-
code: AuthErrorCode;
|
|
170
|
-
message: string;
|
|
171
|
-
} | {
|
|
172
|
-
code: null;
|
|
173
|
-
message: string;
|
|
174
|
-
} | null;
|
|
175
|
-
//#endregion
|
|
176
|
-
export { AUTH_ERRORS, AuthErrorCode, isAuthError, parseAuthError, throwAuthError };
|
|
177
|
-
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","names":[],"sources":["../../src/server/errors.ts"],"mappings":";;;;;;;;;;;;;;;cAmCa,WAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmID,aAAA,gBAA6B,WAAA;;;;;AA0FzC;;;;;;;;;;;;;;;;;;;;iBA5DgB,cAAA,CACd,IAAA,EAAM,aAAA,EACN,OAAA,WACA,OAAA,GAAU,MAAA;;;;;;;;;;;;;;;iBAuBI,WAAA,CACd,KAAA,YACC,KAAA,IAAS,WAAA;EAAc,IAAA,EAAM,aAAA;EAAe,OAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;iBAgC/B,cAAA,CACd,KAAA;EAEI,IAAA,EAAM,aAAA;EAAe,OAAA;AAAA;EACrB,IAAA;EAAY,OAAA;AAAA"}
|
package/dist/server/errors.js
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { ConvexError } from "convex/values";
|
|
2
|
-
|
|
3
|
-
//#region src/server/errors.ts
|
|
4
|
-
/**
|
|
5
|
-
* Structured error handling for Convex Auth.
|
|
6
|
-
*
|
|
7
|
-
* Every error thrown by the auth system uses `ConvexError` with a
|
|
8
|
-
* `{ code, message }` payload so clients can distinguish error types
|
|
9
|
-
* and display user-friendly messages.
|
|
10
|
-
*
|
|
11
|
-
* **Consumer API:** Use {@link throwAuthError} to throw structured errors
|
|
12
|
-
* from your own Convex functions (e.g. custom authorization checks).
|
|
13
|
-
*
|
|
14
|
-
* **Internal pattern:** The library itself uses `new AuthError(code)` with
|
|
15
|
-
* the `@robelest/fx` effect system (`Fx.fail(new AuthError(code))`).
|
|
16
|
-
* You do not need to use `AuthError` directly — it is an implementation detail.
|
|
17
|
-
*
|
|
18
|
-
* @module
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Map of every auth error code to its default human-readable message.
|
|
22
|
-
*
|
|
23
|
-
* Use the keys as the `code` argument to {@link throwAuthError}.
|
|
24
|
-
* Clients can match on these codes for conditional error handling.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* throwAuthError("NOT_SIGNED_IN");
|
|
29
|
-
* // ConvexError { data: { code: "NOT_SIGNED_IN", message: "You must be signed in..." } }
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
const AUTH_ERRORS = {
|
|
33
|
-
PROVIDER_NOT_CONFIGURED: "This sign-in method is not available.",
|
|
34
|
-
EMAIL_CONFIG_REQUIRED: "Email transport is not configured. Configure email in createAuth(...).",
|
|
35
|
-
MISSING_ENV_VAR: "A required server environment variable is missing.",
|
|
36
|
-
MISSING_ACTION_CONTEXT: "Action context is required for this operation.",
|
|
37
|
-
INVALID_PARAMETERS: "The provided parameters are invalid.",
|
|
38
|
-
NOT_SIGNED_IN: "You must be signed in to perform this action.",
|
|
39
|
-
INVALID_VERIFICATION_CODE: "Invalid or expired verification code.",
|
|
40
|
-
INVALID_REFRESH_TOKEN: "Your session has expired. Please sign in again.",
|
|
41
|
-
AUTH_HANDSHAKE_TIMEOUT: "Sign-in succeeded but authentication confirmation timed out.",
|
|
42
|
-
AUTH_HANDSHAKE_REJECTED: "Authentication was rejected while confirming the session.",
|
|
43
|
-
SIGN_IN_MISSING_PARAMS: "Cannot sign in: missing provider, code, or refresh token.",
|
|
44
|
-
UNSUPPORTED_PROVIDER_TYPE: "This provider type is not supported.",
|
|
45
|
-
INVALID_REDIRECT: "Invalid redirect URL.",
|
|
46
|
-
EMAIL_SEND_FAILED: "Failed to send verification email. Please try again.",
|
|
47
|
-
INVALID_API_KEY: "Invalid API key.",
|
|
48
|
-
API_KEY_REVOKED: "This API key has been revoked.",
|
|
49
|
-
API_KEY_EXPIRED: "This API key has expired.",
|
|
50
|
-
API_KEY_RATE_LIMITED: "API key rate limit exceeded. Please try again later.",
|
|
51
|
-
API_KEY_INVALID_SCOPE: "Invalid scope requested for API key.",
|
|
52
|
-
KEY_NOT_FOUND: "API key not found.",
|
|
53
|
-
MISSING_BEARER_TOKEN: "Missing or malformed Authorization: Bearer header.",
|
|
54
|
-
SCOPE_CHECK_FAILED: "This API key does not have the required permissions.",
|
|
55
|
-
OAUTH_MISSING_PROVIDER: "Missing OAuth provider ID.",
|
|
56
|
-
OAUTH_MISSING_VERIFIER: "Missing sign-in verifier.",
|
|
57
|
-
OAUTH_INVALID_STATE: "Invalid OAuth state. Please try signing in again.",
|
|
58
|
-
OAUTH_PROVIDER_ERROR: "The sign-in provider returned an error.",
|
|
59
|
-
OAUTH_MISSING_ID_TOKEN: "ID token claims are missing from the provider response.",
|
|
60
|
-
OAUTH_INVALID_PROFILE: "The sign-in provider returned an invalid profile.",
|
|
61
|
-
OAUTH_UNSUPPORTED_AUTH_METHOD: "Unsupported OAuth client authentication method.",
|
|
62
|
-
OAUTH_NO_USERINFO: "No userinfo endpoint configured for this provider.",
|
|
63
|
-
ACCOUNT_ALREADY_EXISTS: "An account with these credentials already exists.",
|
|
64
|
-
ACCOUNT_NOT_FOUND: "Account not found.",
|
|
65
|
-
INVALID_CREDENTIALS_PROVIDER: "This provider does not support credential operations.",
|
|
66
|
-
MISSING_CRYPTO_FUNCTION: "This provider is missing a required cryptographic function.",
|
|
67
|
-
USER_UPDATE_FAILED: "Could not update the user record.",
|
|
68
|
-
INVALID_VERIFIER: "Invalid or expired verifier.",
|
|
69
|
-
PASSKEY_MISSING_CONFIG: "Passkey provider requires SITE_URL or explicit rpId configuration.",
|
|
70
|
-
PASSKEY_AUTH_REQUIRED: "Sign in first, then add a passkey to your account.",
|
|
71
|
-
PASSKEY_MISSING_VERIFIER: "Missing verifier for passkey operation.",
|
|
72
|
-
PASSKEY_INVALID_CLIENT_DATA: "Invalid passkey client data.",
|
|
73
|
-
PASSKEY_INVALID_ORIGIN: "Passkey origin does not match the expected value.",
|
|
74
|
-
PASSKEY_INVALID_CHALLENGE: "Invalid or expired passkey challenge.",
|
|
75
|
-
PASSKEY_RP_MISMATCH: "Relying party ID mismatch.",
|
|
76
|
-
PASSKEY_USER_PRESENCE: "User presence flag not set.",
|
|
77
|
-
PASSKEY_USER_VERIFICATION: "User verification required but not performed.",
|
|
78
|
-
PASSKEY_NO_CREDENTIAL: "No credential in attestation.",
|
|
79
|
-
PASSKEY_UNSUPPORTED_ALGORITHM: "Unsupported passkey algorithm.",
|
|
80
|
-
PASSKEY_INVALID_SIGNATURE: "Invalid passkey signature.",
|
|
81
|
-
PASSKEY_UNKNOWN_CREDENTIAL: "Unknown passkey credential.",
|
|
82
|
-
PASSKEY_COUNTER_ERROR: "Authenticator counter did not increase — possible credential cloning detected.",
|
|
83
|
-
PASSKEY_MISSING_FLOW: "Missing passkey flow parameter.",
|
|
84
|
-
PASSKEY_UNKNOWN_FLOW: "Unknown passkey flow.",
|
|
85
|
-
TOTP_AUTH_REQUIRED: "Sign in first, then set up two-factor authentication.",
|
|
86
|
-
TOTP_MISSING_VERIFIER: "Missing verifier for TOTP operation.",
|
|
87
|
-
TOTP_MISSING_CODE: "Missing TOTP code.",
|
|
88
|
-
TOTP_MISSING_ID: "Missing TOTP enrollment ID.",
|
|
89
|
-
TOTP_NOT_FOUND: "TOTP enrollment not found.",
|
|
90
|
-
TOTP_ALREADY_VERIFIED: "TOTP enrollment is already verified.",
|
|
91
|
-
TOTP_INVALID_CODE: "Invalid TOTP code.",
|
|
92
|
-
TOTP_INVALID_VERIFIER: "Invalid or expired TOTP verifier.",
|
|
93
|
-
TOTP_NO_ENROLLMENT: "No verified TOTP enrollment found.",
|
|
94
|
-
TOTP_MISSING_FLOW: "Missing TOTP flow parameter.",
|
|
95
|
-
TOTP_UNKNOWN_FLOW: "Unknown TOTP flow.",
|
|
96
|
-
DEVICE_CODE_EXPIRED: "The device code has expired. Please start a new authorization request.",
|
|
97
|
-
DEVICE_CODE_DENIED: "The authorization request was denied.",
|
|
98
|
-
DEVICE_AUTHORIZATION_PENDING: "The user has not yet authorized this device.",
|
|
99
|
-
DEVICE_SLOW_DOWN: "Polling too frequently. Increase the interval between requests.",
|
|
100
|
-
DEVICE_INVALID_USER_CODE: "Invalid or expired user code.",
|
|
101
|
-
DEVICE_ALREADY_AUTHORIZED: "This device code has already been authorized.",
|
|
102
|
-
DEVICE_MISSING_FLOW: "Missing device flow parameter.",
|
|
103
|
-
DEVICE_UNKNOWN_FLOW: "Unknown device flow.",
|
|
104
|
-
INVITE_EXPIRED: "This invitation has expired.",
|
|
105
|
-
INVITE_EMAIL_MISMATCH: "This invitation is for a different email.",
|
|
106
|
-
INVITE_ALREADY_ACCEPTED: "This invitation has already been accepted.",
|
|
107
|
-
DUPLICATE_INVITE: "A pending invite already exists for this email in this group.",
|
|
108
|
-
INVITE_NOT_FOUND: "Invite not found.",
|
|
109
|
-
INVITE_NOT_PENDING: "Cannot accept or revoke invite that is not pending.",
|
|
110
|
-
FORBIDDEN: "Access denied.",
|
|
111
|
-
NO_ACTIVE_GROUP: "User has no active group set.",
|
|
112
|
-
DUPLICATE_MEMBERSHIP: "User is already a member of this group.",
|
|
113
|
-
ENTERPRISE_ALREADY_EXISTS: "An enterprise record already exists for this group.",
|
|
114
|
-
ENTERPRISE_DOMAIN_TAKEN: "That domain is already attached to another enterprise.",
|
|
115
|
-
INTERNAL_ERROR: "An unexpected error occurred."
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Throw a structured `ConvexError` with `{ code, message }`.
|
|
119
|
-
*
|
|
120
|
-
* Use this in your own Convex functions (queries, mutations, actions)
|
|
121
|
-
* to throw auth-domain errors that clients can match on by `code`.
|
|
122
|
-
* The library itself uses `AuthError` internally, but consumers
|
|
123
|
-
* should prefer this helper for simplicity.
|
|
124
|
-
*
|
|
125
|
-
* @param code Machine-readable error code from `AUTH_ERRORS`.
|
|
126
|
-
* @param message Optional override for the default human-readable message.
|
|
127
|
-
* @param context Optional extra fields merged into the error payload.
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```ts
|
|
131
|
-
* import { throwAuthError } from "@robelest/convex-auth/server";
|
|
132
|
-
*
|
|
133
|
-
* // In a custom mutation:
|
|
134
|
-
* if (!isAdmin) {
|
|
135
|
-
* throwAuthError("FORBIDDEN");
|
|
136
|
-
* }
|
|
137
|
-
* ```
|
|
138
|
-
*
|
|
139
|
-
* @throws {ConvexError} Always — throws a `ConvexError` with `{ code, message }` payload.
|
|
140
|
-
*/
|
|
141
|
-
function throwAuthError(code, message, context) {
|
|
142
|
-
throw new ConvexError({
|
|
143
|
-
code,
|
|
144
|
-
message: message ?? AUTH_ERRORS[code],
|
|
145
|
-
...context
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Type guard: check whether a caught value is a structured auth `ConvexError`.
|
|
150
|
-
*
|
|
151
|
-
* @param error - The caught value (typically from a `catch` block).
|
|
152
|
-
* @returns `true` when `error` is a `ConvexError` with `{ code, message }` data.
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```ts
|
|
156
|
-
* try { await auth.signIn('email', { email }); }
|
|
157
|
-
* catch (e) {
|
|
158
|
-
* if (isAuthError(e)) console.log(e.data.code); // "EMAIL_SEND_FAILED"
|
|
159
|
-
* }
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
function isAuthError(error) {
|
|
163
|
-
return error instanceof ConvexError && typeof error.data === "object" && error.data !== null && "code" in error.data && "message" in error.data;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Extract `{ code, message }` from a caught error.
|
|
167
|
-
*
|
|
168
|
-
* Works for `ConvexError` (from Convex actions), plain `Error`
|
|
169
|
-
* instances, and structured auth errors. Returns `null` when the
|
|
170
|
-
* value is not an error object.
|
|
171
|
-
*
|
|
172
|
-
* @param error - The caught value to parse.
|
|
173
|
-
* @returns `{ code, message }` when extractable, or `null`.
|
|
174
|
-
* When `code` is `null`, the error is not a structured auth error
|
|
175
|
-
* but `message` still contains the error text.
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* ```ts
|
|
179
|
-
* try {
|
|
180
|
-
* await auth.signIn("email", { email });
|
|
181
|
-
* } catch (e) {
|
|
182
|
-
* const err = parseAuthError(e);
|
|
183
|
-
* if (err?.code === "EMAIL_SEND_FAILED") { ... }
|
|
184
|
-
* }
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
|
-
function parseAuthError(error) {
|
|
188
|
-
if (isAuthError(error)) {
|
|
189
|
-
const { code, message } = error.data;
|
|
190
|
-
return {
|
|
191
|
-
code,
|
|
192
|
-
message
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
if (error instanceof Error && "_tag" in error && error._tag === "AuthError" && "code" in error && typeof error.code === "string") return {
|
|
196
|
-
code: error.code,
|
|
197
|
-
message: error.message
|
|
198
|
-
};
|
|
199
|
-
if (error instanceof ConvexError && typeof error.data === "string") return {
|
|
200
|
-
code: null,
|
|
201
|
-
message: error.data
|
|
202
|
-
};
|
|
203
|
-
if (error instanceof Error) return {
|
|
204
|
-
code: null,
|
|
205
|
-
message: error.message
|
|
206
|
-
};
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
//#endregion
|
|
211
|
-
export { AUTH_ERRORS, isAuthError, parseAuthError, throwAuthError };
|
|
212
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../../src/server/errors.ts"],"sourcesContent":["/**\n * Structured error handling for Convex Auth.\n *\n * Every error thrown by the auth system uses `ConvexError` with a\n * `{ code, message }` payload so clients can distinguish error types\n * and display user-friendly messages.\n *\n * **Consumer API:** Use {@link throwAuthError} to throw structured errors\n * from your own Convex functions (e.g. custom authorization checks).\n *\n * **Internal pattern:** The library itself uses `new AuthError(code)` with\n * the `@robelest/fx` effect system (`Fx.fail(new AuthError(code))`).\n * You do not need to use `AuthError` directly — it is an implementation detail.\n *\n * @module\n */\n\nimport { ConvexError } from \"convex/values\";\n\n// ============================================================================\n// Error code → default message map (single source of truth)\n// ============================================================================\n\n/**\n * Map of every auth error code to its default human-readable message.\n *\n * Use the keys as the `code` argument to {@link throwAuthError}.\n * Clients can match on these codes for conditional error handling.\n *\n * @example\n * ```ts\n * throwAuthError(\"NOT_SIGNED_IN\");\n * // ConvexError { data: { code: \"NOT_SIGNED_IN\", message: \"You must be signed in...\" } }\n * ```\n */\nexport const AUTH_ERRORS = {\n // ---- Configuration ----\n PROVIDER_NOT_CONFIGURED: \"This sign-in method is not available.\",\n EMAIL_CONFIG_REQUIRED:\n \"Email transport is not configured. Configure email in createAuth(...).\",\n MISSING_ENV_VAR: \"A required server environment variable is missing.\",\n MISSING_ACTION_CONTEXT: \"Action context is required for this operation.\",\n INVALID_PARAMETERS: \"The provided parameters are invalid.\",\n\n // ---- Authentication ----\n NOT_SIGNED_IN: \"You must be signed in to perform this action.\",\n INVALID_VERIFICATION_CODE: \"Invalid or expired verification code.\",\n INVALID_REFRESH_TOKEN: \"Your session has expired. Please sign in again.\",\n AUTH_HANDSHAKE_TIMEOUT:\n \"Sign-in succeeded but authentication confirmation timed out.\",\n AUTH_HANDSHAKE_REJECTED:\n \"Authentication was rejected while confirming the session.\",\n SIGN_IN_MISSING_PARAMS:\n \"Cannot sign in: missing provider, code, or refresh token.\",\n UNSUPPORTED_PROVIDER_TYPE: \"This provider type is not supported.\",\n INVALID_REDIRECT: \"Invalid redirect URL.\",\n\n // ---- Email / Phone ----\n EMAIL_SEND_FAILED: \"Failed to send verification email. Please try again.\",\n\n // ---- API Keys ----\n INVALID_API_KEY: \"Invalid API key.\",\n API_KEY_REVOKED: \"This API key has been revoked.\",\n API_KEY_EXPIRED: \"This API key has expired.\",\n API_KEY_RATE_LIMITED: \"API key rate limit exceeded. Please try again later.\",\n API_KEY_INVALID_SCOPE: \"Invalid scope requested for API key.\",\n KEY_NOT_FOUND: \"API key not found.\",\n\n // ---- HTTP Bearer Auth ----\n MISSING_BEARER_TOKEN: \"Missing or malformed Authorization: Bearer header.\",\n SCOPE_CHECK_FAILED: \"This API key does not have the required permissions.\",\n\n // ---- OAuth ----\n OAUTH_MISSING_PROVIDER: \"Missing OAuth provider ID.\",\n OAUTH_MISSING_VERIFIER: \"Missing sign-in verifier.\",\n OAUTH_INVALID_STATE: \"Invalid OAuth state. Please try signing in again.\",\n OAUTH_PROVIDER_ERROR: \"The sign-in provider returned an error.\",\n OAUTH_MISSING_ID_TOKEN:\n \"ID token claims are missing from the provider response.\",\n OAUTH_INVALID_PROFILE: \"The sign-in provider returned an invalid profile.\",\n OAUTH_UNSUPPORTED_AUTH_METHOD:\n \"Unsupported OAuth client authentication method.\",\n OAUTH_NO_USERINFO: \"No userinfo endpoint configured for this provider.\",\n\n // ---- Credentials ----\n ACCOUNT_ALREADY_EXISTS: \"An account with these credentials already exists.\",\n ACCOUNT_NOT_FOUND: \"Account not found.\",\n INVALID_CREDENTIALS_PROVIDER:\n \"This provider does not support credential operations.\",\n MISSING_CRYPTO_FUNCTION:\n \"This provider is missing a required cryptographic function.\",\n USER_UPDATE_FAILED: \"Could not update the user record.\",\n\n // ---- Verifier ----\n INVALID_VERIFIER: \"Invalid or expired verifier.\",\n\n // ---- Passkey ----\n PASSKEY_MISSING_CONFIG:\n \"Passkey provider requires SITE_URL or explicit rpId configuration.\",\n PASSKEY_AUTH_REQUIRED: \"Sign in first, then add a passkey to your account.\",\n PASSKEY_MISSING_VERIFIER: \"Missing verifier for passkey operation.\",\n PASSKEY_INVALID_CLIENT_DATA: \"Invalid passkey client data.\",\n PASSKEY_INVALID_ORIGIN: \"Passkey origin does not match the expected value.\",\n PASSKEY_INVALID_CHALLENGE: \"Invalid or expired passkey challenge.\",\n PASSKEY_RP_MISMATCH: \"Relying party ID mismatch.\",\n PASSKEY_USER_PRESENCE: \"User presence flag not set.\",\n PASSKEY_USER_VERIFICATION: \"User verification required but not performed.\",\n PASSKEY_NO_CREDENTIAL: \"No credential in attestation.\",\n PASSKEY_UNSUPPORTED_ALGORITHM: \"Unsupported passkey algorithm.\",\n PASSKEY_INVALID_SIGNATURE: \"Invalid passkey signature.\",\n PASSKEY_UNKNOWN_CREDENTIAL: \"Unknown passkey credential.\",\n PASSKEY_COUNTER_ERROR:\n \"Authenticator counter did not increase — possible credential cloning detected.\",\n PASSKEY_MISSING_FLOW: \"Missing passkey flow parameter.\",\n PASSKEY_UNKNOWN_FLOW: \"Unknown passkey flow.\",\n\n // ---- TOTP ----\n TOTP_AUTH_REQUIRED: \"Sign in first, then set up two-factor authentication.\",\n TOTP_MISSING_VERIFIER: \"Missing verifier for TOTP operation.\",\n TOTP_MISSING_CODE: \"Missing TOTP code.\",\n TOTP_MISSING_ID: \"Missing TOTP enrollment ID.\",\n TOTP_NOT_FOUND: \"TOTP enrollment not found.\",\n TOTP_ALREADY_VERIFIED: \"TOTP enrollment is already verified.\",\n TOTP_INVALID_CODE: \"Invalid TOTP code.\",\n TOTP_INVALID_VERIFIER: \"Invalid or expired TOTP verifier.\",\n TOTP_NO_ENROLLMENT: \"No verified TOTP enrollment found.\",\n TOTP_MISSING_FLOW: \"Missing TOTP flow parameter.\",\n TOTP_UNKNOWN_FLOW: \"Unknown TOTP flow.\",\n\n // ---- Device Authorization (RFC 8628) ----\n DEVICE_CODE_EXPIRED:\n \"The device code has expired. Please start a new authorization request.\",\n DEVICE_CODE_DENIED: \"The authorization request was denied.\",\n DEVICE_AUTHORIZATION_PENDING: \"The user has not yet authorized this device.\",\n DEVICE_SLOW_DOWN:\n \"Polling too frequently. Increase the interval between requests.\",\n DEVICE_INVALID_USER_CODE: \"Invalid or expired user code.\",\n DEVICE_ALREADY_AUTHORIZED: \"This device code has already been authorized.\",\n DEVICE_MISSING_FLOW: \"Missing device flow parameter.\",\n DEVICE_UNKNOWN_FLOW: \"Unknown device flow.\",\n\n // ---- Invites ----\n INVITE_EXPIRED: \"This invitation has expired.\",\n INVITE_EMAIL_MISMATCH: \"This invitation is for a different email.\",\n INVITE_ALREADY_ACCEPTED: \"This invitation has already been accepted.\",\n DUPLICATE_INVITE:\n \"A pending invite already exists for this email in this group.\",\n INVITE_NOT_FOUND: \"Invite not found.\",\n INVITE_NOT_PENDING: \"Cannot accept or revoke invite that is not pending.\",\n\n // ---- Groups / Members ----\n FORBIDDEN: \"Access denied.\",\n NO_ACTIVE_GROUP: \"User has no active group set.\",\n DUPLICATE_MEMBERSHIP: \"User is already a member of this group.\",\n\n // ---- Enterprise ----\n ENTERPRISE_ALREADY_EXISTS:\n \"An enterprise record already exists for this group.\",\n ENTERPRISE_DOMAIN_TAKEN:\n \"That domain is already attached to another enterprise.\",\n\n // ---- Internal (should never reach user) ----\n INTERNAL_ERROR: \"An unexpected error occurred.\",\n} as const satisfies Record<string, string>;\n\n/** Union of all recognized auth error code strings (keys of {@link AUTH_ERRORS}). */\nexport type AuthErrorCode = keyof typeof AUTH_ERRORS;\n\n// ============================================================================\n// Error helpers\n// ============================================================================\n\n/**\n * Throw a structured `ConvexError` with `{ code, message }`.\n *\n * Use this in your own Convex functions (queries, mutations, actions)\n * to throw auth-domain errors that clients can match on by `code`.\n * The library itself uses `AuthError` internally, but consumers\n * should prefer this helper for simplicity.\n *\n * @param code Machine-readable error code from `AUTH_ERRORS`.\n * @param message Optional override for the default human-readable message.\n * @param context Optional extra fields merged into the error payload.\n *\n * @example\n * ```ts\n * import { throwAuthError } from \"@robelest/convex-auth/server\";\n *\n * // In a custom mutation:\n * if (!isAdmin) {\n * throwAuthError(\"FORBIDDEN\");\n * }\n * ```\n *\n * @throws {ConvexError} Always — throws a `ConvexError` with `{ code, message }` payload.\n */\nexport function throwAuthError(\n code: AuthErrorCode,\n message?: string,\n context?: Record<string, unknown>,\n): never {\n throw new ConvexError({\n code,\n message: message ?? AUTH_ERRORS[code],\n ...context,\n });\n}\n\n/**\n * Type guard: check whether a caught value is a structured auth `ConvexError`.\n *\n * @param error - The caught value (typically from a `catch` block).\n * @returns `true` when `error` is a `ConvexError` with `{ code, message }` data.\n *\n * @example\n * ```ts\n * try { await auth.signIn('email', { email }); }\n * catch (e) {\n * if (isAuthError(e)) console.log(e.data.code); // \"EMAIL_SEND_FAILED\"\n * }\n * ```\n */\nexport function isAuthError(\n error: unknown,\n): error is ConvexError<{ code: AuthErrorCode; message: string }> {\n return (\n error instanceof ConvexError &&\n typeof error.data === \"object\" &&\n error.data !== null &&\n \"code\" in error.data &&\n \"message\" in error.data\n );\n}\n\n/**\n * Extract `{ code, message }` from a caught error.\n *\n * Works for `ConvexError` (from Convex actions), plain `Error`\n * instances, and structured auth errors. Returns `null` when the\n * value is not an error object.\n *\n * @param error - The caught value to parse.\n * @returns `{ code, message }` when extractable, or `null`.\n * When `code` is `null`, the error is not a structured auth error\n * but `message` still contains the error text.\n *\n * @example\n * ```ts\n * try {\n * await auth.signIn(\"email\", { email });\n * } catch (e) {\n * const err = parseAuthError(e);\n * if (err?.code === \"EMAIL_SEND_FAILED\") { ... }\n * }\n * ```\n */\nexport function parseAuthError(\n error: unknown,\n):\n | { code: AuthErrorCode; message: string }\n | { code: null; message: string }\n | null {\n if (isAuthError(error)) {\n const { code, message } = error.data as {\n code: AuthErrorCode;\n message: string;\n };\n return { code, message };\n }\n // Recognize the Fx-native AuthError class (has _tag + code)\n if (\n error instanceof Error &&\n \"_tag\" in error &&\n (error as any)._tag === \"AuthError\" &&\n \"code\" in error &&\n typeof (error as any).code === \"string\"\n ) {\n return {\n code: (error as any).code as AuthErrorCode,\n message: error.message,\n };\n }\n if (error instanceof ConvexError && typeof error.data === \"string\") {\n return { code: null, message: error.data };\n }\n if (error instanceof Error) {\n return { code: null, message: error.message };\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,cAAc;CAEzB,yBAAyB;CACzB,uBACE;CACF,iBAAiB;CACjB,wBAAwB;CACxB,oBAAoB;CAGpB,eAAe;CACf,2BAA2B;CAC3B,uBAAuB;CACvB,wBACE;CACF,yBACE;CACF,wBACE;CACF,2BAA2B;CAC3B,kBAAkB;CAGlB,mBAAmB;CAGnB,iBAAiB;CACjB,iBAAiB;CACjB,iBAAiB;CACjB,sBAAsB;CACtB,uBAAuB;CACvB,eAAe;CAGf,sBAAsB;CACtB,oBAAoB;CAGpB,wBAAwB;CACxB,wBAAwB;CACxB,qBAAqB;CACrB,sBAAsB;CACtB,wBACE;CACF,uBAAuB;CACvB,+BACE;CACF,mBAAmB;CAGnB,wBAAwB;CACxB,mBAAmB;CACnB,8BACE;CACF,yBACE;CACF,oBAAoB;CAGpB,kBAAkB;CAGlB,wBACE;CACF,uBAAuB;CACvB,0BAA0B;CAC1B,6BAA6B;CAC7B,wBAAwB;CACxB,2BAA2B;CAC3B,qBAAqB;CACrB,uBAAuB;CACvB,2BAA2B;CAC3B,uBAAuB;CACvB,+BAA+B;CAC/B,2BAA2B;CAC3B,4BAA4B;CAC5B,uBACE;CACF,sBAAsB;CACtB,sBAAsB;CAGtB,oBAAoB;CACpB,uBAAuB;CACvB,mBAAmB;CACnB,iBAAiB;CACjB,gBAAgB;CAChB,uBAAuB;CACvB,mBAAmB;CACnB,uBAAuB;CACvB,oBAAoB;CACpB,mBAAmB;CACnB,mBAAmB;CAGnB,qBACE;CACF,oBAAoB;CACpB,8BAA8B;CAC9B,kBACE;CACF,0BAA0B;CAC1B,2BAA2B;CAC3B,qBAAqB;CACrB,qBAAqB;CAGrB,gBAAgB;CAChB,uBAAuB;CACvB,yBAAyB;CACzB,kBACE;CACF,kBAAkB;CAClB,oBAAoB;CAGpB,WAAW;CACX,iBAAiB;CACjB,sBAAsB;CAGtB,2BACE;CACF,yBACE;CAGF,gBAAgB;CACjB;;;;;;;;;;;;;;;;;;;;;;;;;AAiCD,SAAgB,eACd,MACA,SACA,SACO;AACP,OAAM,IAAI,YAAY;EACpB;EACA,SAAS,WAAW,YAAY;EAChC,GAAG;EACJ,CAAC;;;;;;;;;;;;;;;;AAiBJ,SAAgB,YACd,OACgE;AAChE,QACE,iBAAiB,eACjB,OAAO,MAAM,SAAS,YACtB,MAAM,SAAS,QACf,UAAU,MAAM,QAChB,aAAa,MAAM;;;;;;;;;;;;;;;;;;;;;;;;AA0BvB,SAAgB,eACd,OAIO;AACP,KAAI,YAAY,MAAM,EAAE;EACtB,MAAM,EAAE,MAAM,YAAY,MAAM;AAIhC,SAAO;GAAE;GAAM;GAAS;;AAG1B,KACE,iBAAiB,SACjB,UAAU,SACT,MAAc,SAAS,eACxB,UAAU,SACV,OAAQ,MAAc,SAAS,SAE/B,QAAO;EACL,MAAO,MAAc;EACrB,SAAS,MAAM;EAChB;AAEH,KAAI,iBAAiB,eAAe,OAAO,MAAM,SAAS,SACxD,QAAO;EAAE,MAAM;EAAM,SAAS,MAAM;EAAM;AAE5C,KAAI,iBAAiB,MACnB,QAAO;EAAE,MAAM;EAAM,SAAS,MAAM;EAAS;AAE/C,QAAO"}
|
package/src/server/authError.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Cv } from "@robelest/fx/convex";
|
|
2
|
-
import type { ConvexError } from "convex/values";
|
|
3
|
-
|
|
4
|
-
import { AUTH_ERRORS } from "./errors";
|
|
5
|
-
import type { AuthErrorCode } from "./errors";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Typed error for the Fx error channel.
|
|
9
|
-
*
|
|
10
|
-
* Use with `Fx.fail(new AuthError("CODE"))` in pipelines.
|
|
11
|
-
* At Convex boundaries, {@link toConvexError} converts these to `ConvexError`.
|
|
12
|
-
*/
|
|
13
|
-
export class AuthError extends Error {
|
|
14
|
-
/**
|
|
15
|
-
* Discriminant tag for error channel matching.
|
|
16
|
-
* @readonly
|
|
17
|
-
*/
|
|
18
|
-
readonly _tag = "AuthError" as const;
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
/**
|
|
22
|
-
* Machine-readable error code.
|
|
23
|
-
* @readonly
|
|
24
|
-
*/
|
|
25
|
-
readonly code: AuthErrorCode,
|
|
26
|
-
message?: string,
|
|
27
|
-
/**
|
|
28
|
-
* Optional structured context for diagnostics.
|
|
29
|
-
* @readonly
|
|
30
|
-
*/
|
|
31
|
-
readonly context?: Record<string, unknown>,
|
|
32
|
-
) {
|
|
33
|
-
super(message ?? AUTH_ERRORS[code]);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Convert to the `ConvexError` shape the Convex runtime expects. */
|
|
37
|
-
toConvexError(): ConvexError<{ code: AuthErrorCode; message: string }> {
|
|
38
|
-
return Cv.error({
|
|
39
|
-
code: this.code,
|
|
40
|
-
message: this.message,
|
|
41
|
-
...this.context,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|