better-auth 1.7.12 → 1.7.14
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/adapters/index.d.mts +5 -10
- package/dist/api/dispatch.d.mts +3 -5
- package/dist/api/dispatch.mjs +6 -4
- package/dist/api/index.d.mts +506 -508
- package/dist/api/index.mjs +35 -34
- package/dist/api/middlewares/authorization.d.mts +15 -12
- package/dist/api/middlewares/authorization.mjs +2 -1
- package/dist/api/middlewares/index.d.mts +2 -1
- package/dist/api/middlewares/origin-check.d.mts +4 -7
- package/dist/api/routes/account.d.mts +11 -15
- package/dist/api/routes/account.mjs +7 -4
- package/dist/api/routes/callback.d.mts +2 -5
- package/dist/api/routes/callback.mjs +4 -2
- package/dist/api/routes/email-verification.d.mts +7 -12
- package/dist/api/routes/error.d.mts +2 -5
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +2 -5
- package/dist/api/routes/password.d.mts +8 -11
- package/dist/api/routes/password.mjs +3 -2
- package/dist/api/routes/session.d.mts +26 -29
- package/dist/api/routes/sign-in.d.mts +4 -6
- package/dist/api/routes/sign-out.d.mts +2 -5
- package/dist/api/routes/sign-up.d.mts +4 -6
- package/dist/api/routes/update-session.d.mts +4 -6
- package/dist/api/routes/update-user.d.mts +14 -16
- package/dist/api/routes/update-user.mjs +1 -1
- package/dist/api/state/oauth.d.mts +0 -3
- package/dist/api/state/oauth.mjs +2 -1
- package/dist/auth/full.d.mts +3 -4
- package/dist/auth/minimal.d.mts +3 -3
- package/dist/client/broadcast-channel.d.mts +6 -7
- package/dist/client/config.d.mts +15 -19
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +3 -5
- package/dist/client/focus-manager.d.mts +4 -5
- package/dist/client/index.d.mts +8 -7
- package/dist/client/lynx/index.d.mts +6 -7
- package/dist/client/lynx/index.mjs +3 -2
- package/dist/client/lynx/lynx-store.d.mts +3 -4
- package/dist/client/online-manager.d.mts +4 -5
- package/dist/client/parser.d.mts +9 -5
- package/dist/client/path-to-object.d.mts +13 -14
- package/dist/client/plugins/index.d.mts +1 -1
- package/dist/client/plugins/infer-plugin.d.mts +2 -4
- package/dist/client/query.d.mts +4 -6
- package/dist/client/react/index.d.mts +6 -7
- package/dist/client/react/index.mjs +3 -2
- package/dist/client/react/react-store.d.mts +3 -4
- package/dist/client/session-atom.d.mts +4 -4
- package/dist/client/session-refresh.d.mts +3 -5
- package/dist/client/solid/index.d.mts +6 -7
- package/dist/client/solid/index.mjs +3 -2
- package/dist/client/svelte/index.d.mts +6 -7
- package/dist/client/svelte/index.mjs +3 -2
- package/dist/client/types.d.mts +11 -11
- package/dist/client/vanilla.d.mts +4 -5
- package/dist/client/vanilla.mjs +3 -2
- package/dist/client/vue/index.d.mts +6 -7
- package/dist/client/vue/index.mjs +3 -2
- package/dist/context/create-context.mjs +7 -7
- package/dist/context/helpers.mjs +9 -7
- package/dist/cookies/cookie-utils.d.mts +13 -13
- package/dist/cookies/cookie-utils.mjs +1 -3
- package/dist/cookies/index.d.mts +17 -18
- package/dist/cookies/index.mjs +11 -7
- package/dist/cookies/jwt.mjs +2 -1
- package/dist/cookies/session-store.d.mts +6 -5
- package/dist/cookies/session-store.mjs +3 -2
- package/dist/crypto/buffer.d.mts +2 -3
- package/dist/crypto/index.d.mts +9 -16
- package/dist/crypto/index.mjs +2 -1
- package/dist/crypto/jwt.d.mts +5 -7
- package/dist/crypto/jwt.mjs +2 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/crypto/random.d.mts +2 -3
- package/dist/db/adapter-base.d.mts +2 -4
- package/dist/db/adapter-kysely.d.mts +2 -4
- package/dist/db/field-converter.d.mts +3 -5
- package/dist/db/field.d.mts +11 -12
- package/dist/db/get-migration.d.mts +4 -8
- package/dist/db/get-migration.mjs +22 -22
- package/dist/db/get-schema.d.mts +2 -4
- package/dist/db/internal-adapter.d.mts +2 -4
- package/dist/db/internal-adapter.mjs +6 -4
- package/dist/db/revoke-unproven-account-access.d.mts +3 -4
- package/dist/db/schema.d.mts +15 -16
- package/dist/db/schema.mjs +6 -3
- package/dist/db/to-zod.d.mts +5 -9
- package/dist/db/with-hooks.d.mts +3 -5
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +7 -11
- package/dist/integrations/node.d.mts +5 -7
- package/dist/integrations/node.mjs +4 -2
- package/dist/integrations/solid-start.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +6 -14
- package/dist/integrations/tanstack-start-solid.d.mts +4 -8
- package/dist/integrations/tanstack-start.d.mts +4 -8
- package/dist/oauth2/link-account.d.mts +5 -11
- package/dist/oauth2/link-account.mjs +12 -6
- package/dist/oauth2/state.d.mts +5 -7
- package/dist/oauth2/state.mjs +1 -1
- package/dist/oauth2/utils.d.mts +4 -6
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +4 -6
- package/dist/plugins/access/index.mjs +1 -2
- package/dist/plugins/access/types.d.mts +12 -14
- package/dist/plugins/additional-fields/client.d.mts +2 -4
- package/dist/plugins/admin/access/index.mjs +1 -2
- package/dist/plugins/admin/access/statement.d.mts +7 -7
- package/dist/plugins/admin/admin.d.mts +122 -128
- package/dist/plugins/admin/client.d.mts +32 -32
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +25 -28
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/index.mjs +1 -2
- package/dist/plugins/admin/schema.d.mts +3 -4
- package/dist/plugins/admin/types.d.mts +8 -8
- package/dist/plugins/anonymous/client.d.mts +10 -12
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +10 -13
- package/dist/plugins/anonymous/index.d.mts +17 -21
- package/dist/plugins/anonymous/schema.d.mts +2 -3
- package/dist/plugins/anonymous/types.d.mts +5 -6
- package/dist/plugins/bearer/index.d.mts +7 -11
- package/dist/plugins/captcha/constants.d.mts +2 -3
- package/dist/plugins/captcha/index.d.mts +6 -9
- package/dist/plugins/captcha/types.d.mts +11 -13
- package/dist/plugins/custom-session/client.d.mts +2 -4
- package/dist/plugins/custom-session/index.d.mts +10 -16
- package/dist/plugins/device-authorization/client.d.mts +2 -4
- package/dist/plugins/device-authorization/index.d.mts +39 -44
- package/dist/plugins/device-authorization/index.mjs +10 -9
- package/dist/plugins/device-authorization/routes.d.mts +7 -5
- package/dist/plugins/device-authorization/routes.mjs +6 -5
- package/dist/plugins/device-authorization/schema.d.mts +2 -3
- package/dist/plugins/email-otp/client.d.mts +5 -7
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +5 -8
- package/dist/plugins/email-otp/index.d.mts +69 -76
- package/dist/plugins/email-otp/otp-token.mjs +19 -7
- package/dist/plugins/email-otp/types.d.mts +2 -4
- package/dist/plugins/generic-oauth/index.d.mts +9 -13
- package/dist/plugins/generic-oauth/index.mjs +6 -4
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +2 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +2 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/line.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/okta.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/slack.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +3 -5
- package/dist/plugins/generic-oauth/types.d.mts +6 -7
- package/dist/plugins/haveibeenpwned/index.d.mts +7 -11
- package/dist/plugins/index.d.mts +4 -1
- package/dist/plugins/jwt/client.d.mts +2 -3
- package/dist/plugins/jwt/index.d.mts +11 -14
- package/dist/plugins/jwt/index.mjs +1 -1
- package/dist/plugins/jwt/schema.d.mts +2 -3
- package/dist/plugins/jwt/sign.d.mts +9 -8
- package/dist/plugins/jwt/types.d.mts +7 -8
- package/dist/plugins/jwt/utils.d.mts +6 -9
- package/dist/plugins/jwt/verify.d.mts +2 -4
- package/dist/plugins/last-login-method/client.d.mts +3 -4
- package/dist/plugins/last-login-method/index.d.mts +5 -9
- package/dist/plugins/last-login-method/index.mjs +1 -1
- package/dist/plugins/magic-link/client.d.mts +2 -4
- package/dist/plugins/magic-link/index.d.mts +7 -10
- package/dist/plugins/magic-link/index.mjs +20 -17
- package/dist/plugins/multi-session/client.d.mts +3 -5
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +3 -6
- package/dist/plugins/multi-session/index.d.mts +10 -14
- package/dist/plugins/oauth-popup/client.d.mts +11 -17
- package/dist/plugins/oauth-popup/client.mjs +6 -4
- package/dist/plugins/oauth-popup/constants.d.mts +5 -6
- package/dist/plugins/oauth-popup/error-codes.d.mts +6 -9
- package/dist/plugins/oauth-popup/index.d.mts +11 -15
- package/dist/plugins/oauth-popup/index.mjs +8 -7
- package/dist/plugins/oauth-popup/types.d.mts +4 -6
- package/dist/plugins/oauth-proxy/index.d.mts +11 -15
- package/dist/plugins/oauth-proxy/index.mjs +10 -7
- package/dist/plugins/one-tap/client.d.mts +6 -9
- package/dist/plugins/one-tap/index.d.mts +4 -7
- package/dist/plugins/one-time-token/client.d.mts +2 -3
- package/dist/plugins/one-time-token/index.d.mts +8 -10
- package/dist/plugins/open-api/generator.d.mts +8 -8
- package/dist/plugins/open-api/generator.mjs +5 -5
- package/dist/plugins/open-api/index.d.mts +5 -7
- package/dist/plugins/organization/access/index.mjs +1 -2
- package/dist/plugins/organization/access/statement.d.mts +8 -8
- package/dist/plugins/organization/adapter.d.mts +60 -87
- package/dist/plugins/organization/adapter.mjs +14 -10
- package/dist/plugins/organization/client.d.mts +108 -107
- package/dist/plugins/organization/client.mjs +9 -5
- package/dist/plugins/organization/error-codes.d.mts +61 -64
- package/dist/plugins/organization/has-permission.d.mts +2 -4
- package/dist/plugins/organization/has-permission.mjs +1 -1
- package/dist/plugins/organization/index.d.mts +1 -1
- package/dist/plugins/organization/organization.d.mts +20 -20
- package/dist/plugins/organization/organization.mjs +13 -8
- package/dist/plugins/organization/permission.d.mts +4 -5
- package/dist/plugins/organization/routes/crud-access-control.d.mts +28 -28
- package/dist/plugins/organization/routes/crud-invites.d.mts +64 -65
- package/dist/plugins/organization/routes/crud-invites.mjs +21 -18
- package/dist/plugins/organization/routes/crud-members.d.mts +53 -56
- package/dist/plugins/organization/routes/crud-members.mjs +23 -21
- package/dist/plugins/organization/routes/crud-org.d.mts +63 -65
- package/dist/plugins/organization/routes/crud-org.mjs +4 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +65 -66
- package/dist/plugins/organization/routes/crud-team.mjs +4 -2
- package/dist/plugins/organization/schema.d.mts +33 -33
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -17
- package/dist/plugins/phone-number/client.d.mts +14 -16
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +14 -17
- package/dist/plugins/phone-number/index.d.mts +48 -54
- package/dist/plugins/phone-number/schema.d.mts +2 -3
- package/dist/plugins/phone-number/types.d.mts +4 -5
- package/dist/plugins/siwe/client.d.mts +2 -4
- package/dist/plugins/siwe/index.d.mts +7 -9
- package/dist/plugins/siwe/index.mjs +1 -1
- package/dist/plugins/siwe/parse-message.mjs +1 -3
- package/dist/plugins/siwe/schema.d.mts +3 -4
- package/dist/plugins/siwe/types.d.mts +4 -4
- package/dist/plugins/test-utils/auth-helpers.mjs +4 -2
- package/dist/plugins/test-utils/index.d.mts +3 -5
- package/dist/plugins/test-utils/types.d.mts +7 -7
- package/dist/plugins/two-factor/backup-codes/index.d.mts +11 -14
- package/dist/plugins/two-factor/backup-codes/index.mjs +12 -6
- package/dist/plugins/two-factor/client.d.mts +16 -19
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/constant.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +15 -18
- package/dist/plugins/two-factor/index.d.mts +31 -35
- package/dist/plugins/two-factor/index.mjs +6 -3
- package/dist/plugins/two-factor/otp/index.d.mts +5 -8
- package/dist/plugins/two-factor/otp/index.mjs +159 -154
- package/dist/plugins/two-factor/schema.d.mts +2 -3
- package/dist/plugins/two-factor/totp/index.d.mts +7 -10
- package/dist/plugins/two-factor/totp/index.mjs +164 -148
- package/dist/plugins/two-factor/types.d.mts +6 -7
- package/dist/plugins/username/client.d.mts +12 -14
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +11 -14
- package/dist/plugins/username/index.d.mts +26 -31
- package/dist/plugins/username/schema.d.mts +7 -10
- package/dist/state.d.mts +4 -5
- package/dist/test-utils/headers.d.mts +2 -3
- package/dist/test-utils/http-test-instance.d.mts +26 -29
- package/dist/test-utils/test-instance.d.mts +7 -6
- package/dist/test-utils/test-instance.mjs +4 -2
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +4 -6
- package/dist/types/auth.d.mts +2 -4
- package/dist/types/helper.d.mts +11 -12
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +4 -5
- package/dist/types/plugins.d.mts +7 -8
- package/dist/utils/hide-metadata.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/is-api-error.mjs +1 -2
- package/dist/utils/time.d.mts +4 -4
- package/dist/utils/url.d.mts +13 -15
- package/dist/utils/wildcard.mjs +5 -3
- package/package.json +12 -12
|
@@ -9,7 +9,18 @@ import { APIError, BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
|
9
9
|
import { createAuthEndpoint } from "@better-auth/core/api";
|
|
10
10
|
import * as z from "zod";
|
|
11
11
|
import { createOTP } from "@better-auth/utils/otp";
|
|
12
|
+
import { base32 } from "@better-auth/utils/base32";
|
|
12
13
|
//#region src/plugins/two-factor/totp/index.ts
|
|
14
|
+
const BASE32_PREFIX = "base32:";
|
|
15
|
+
/**
|
|
16
|
+
* Secrets imported from other providers are stored as `base32:<secret>`.
|
|
17
|
+
* Generated secrets never contain `:`, so they are used as-is.
|
|
18
|
+
*/
|
|
19
|
+
async function decryptTOTPSecret(options) {
|
|
20
|
+
const secret = await symmetricDecrypt(options);
|
|
21
|
+
if (!secret.startsWith(BASE32_PREFIX)) return secret;
|
|
22
|
+
return base32.decode(secret.slice(7).toUpperCase());
|
|
23
|
+
}
|
|
13
24
|
const generateTOTPBodySchema = z.object({ secret: z.string().meta({ description: "The secret to generate the TOTP code" }) });
|
|
14
25
|
const verifyTOTPBodySchema = z.object({
|
|
15
26
|
code: z.string().meta({ description: "The otp code to verify. Eg: \"012345\"" }),
|
|
@@ -29,6 +40,156 @@ const totp2fa = (options) => {
|
|
|
29
40
|
const passwordSchema = z.string().meta({ description: "User password" });
|
|
30
41
|
const getTOTPURIBodySchema = options?.allowPasswordless ? z.object({ password: passwordSchema.optional() }) : z.object({ password: passwordSchema });
|
|
31
42
|
const twoFactorTable = "twoFactor";
|
|
43
|
+
const generateTOTP = createAuthEndpoint.serverOnly({
|
|
44
|
+
method: "POST",
|
|
45
|
+
body: generateTOTPBodySchema,
|
|
46
|
+
metadata: { openapi: {
|
|
47
|
+
summary: "Generate TOTP code",
|
|
48
|
+
description: "Use this endpoint to generate a TOTP code",
|
|
49
|
+
responses: { 200: {
|
|
50
|
+
description: "Successful response",
|
|
51
|
+
content: { "application/json": { schema: {
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: { code: { type: "string" } }
|
|
54
|
+
} } }
|
|
55
|
+
} }
|
|
56
|
+
} }
|
|
57
|
+
}, async (ctx) => {
|
|
58
|
+
if (options?.disable) {
|
|
59
|
+
ctx.context.logger.error("totp isn't configured. please pass totp option on two factor plugin to enable totp");
|
|
60
|
+
throw APIError.from("BAD_REQUEST", {
|
|
61
|
+
message: "totp isn't configured",
|
|
62
|
+
code: "TOTP_NOT_CONFIGURED"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return { code: await createOTP(ctx.body.secret, {
|
|
66
|
+
period: opts.period,
|
|
67
|
+
digits: opts.digits
|
|
68
|
+
}).totp() };
|
|
69
|
+
});
|
|
70
|
+
const getTOTPURI = createAuthEndpoint("/two-factor/get-totp-uri", {
|
|
71
|
+
method: "POST",
|
|
72
|
+
use: [sessionMiddleware],
|
|
73
|
+
body: getTOTPURIBodySchema,
|
|
74
|
+
metadata: { openapi: {
|
|
75
|
+
summary: "Get TOTP URI",
|
|
76
|
+
description: "Use this endpoint to get the TOTP URI",
|
|
77
|
+
responses: { 200: {
|
|
78
|
+
description: "Successful response",
|
|
79
|
+
content: { "application/json": { schema: {
|
|
80
|
+
type: "object",
|
|
81
|
+
properties: { totpURI: { type: "string" } }
|
|
82
|
+
} } }
|
|
83
|
+
} }
|
|
84
|
+
} }
|
|
85
|
+
}, async (ctx) => {
|
|
86
|
+
if (options?.disable) {
|
|
87
|
+
ctx.context.logger.error("totp isn't configured. please pass totp option on two factor plugin to enable totp");
|
|
88
|
+
throw APIError.from("BAD_REQUEST", {
|
|
89
|
+
message: "totp isn't configured",
|
|
90
|
+
code: "TOTP_NOT_CONFIGURED"
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const user = ctx.context.session.user;
|
|
94
|
+
const twoFactor = await ctx.context.adapter.findOne({
|
|
95
|
+
model: twoFactorTable,
|
|
96
|
+
where: [{
|
|
97
|
+
field: "userId",
|
|
98
|
+
value: user.id
|
|
99
|
+
}]
|
|
100
|
+
});
|
|
101
|
+
if (!twoFactor) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.TOTP_NOT_ENABLED);
|
|
102
|
+
const secret = await decryptTOTPSecret({
|
|
103
|
+
key: ctx.context.secretConfig,
|
|
104
|
+
data: twoFactor.secret
|
|
105
|
+
});
|
|
106
|
+
if (await shouldRequirePassword(ctx, user.id, options?.allowPasswordless)) {
|
|
107
|
+
if (!ctx.body.password) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.INVALID_PASSWORD);
|
|
108
|
+
await ctx.context.password.checkPassword(user.id, ctx);
|
|
109
|
+
}
|
|
110
|
+
return { totpURI: createOTP(secret, {
|
|
111
|
+
digits: opts.digits,
|
|
112
|
+
period: opts.period
|
|
113
|
+
}).url(options?.issuer || ctx.context.appName, user.email) };
|
|
114
|
+
});
|
|
115
|
+
const verifyTOTP = createAuthEndpoint("/two-factor/verify-totp", {
|
|
116
|
+
method: "POST",
|
|
117
|
+
body: verifyTOTPBodySchema,
|
|
118
|
+
metadata: { openapi: {
|
|
119
|
+
summary: "Verify two factor TOTP",
|
|
120
|
+
description: "Verify two factor TOTP",
|
|
121
|
+
responses: { 200: {
|
|
122
|
+
description: "Successful response",
|
|
123
|
+
content: { "application/json": { schema: {
|
|
124
|
+
type: "object",
|
|
125
|
+
properties: { status: { type: "boolean" } }
|
|
126
|
+
} } }
|
|
127
|
+
} }
|
|
128
|
+
} }
|
|
129
|
+
}, async (ctx) => {
|
|
130
|
+
if (options?.disable) {
|
|
131
|
+
ctx.context.logger.error("totp isn't configured. please pass totp option on two factor plugin to enable totp");
|
|
132
|
+
throw APIError.from("BAD_REQUEST", {
|
|
133
|
+
message: "totp isn't configured",
|
|
134
|
+
code: "TOTP_NOT_CONFIGURED"
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const { session, valid, invalid, beginAttempt } = await verifyTwoFactor(ctx);
|
|
138
|
+
const user = session.user;
|
|
139
|
+
const isSignIn = !session.session;
|
|
140
|
+
const twoFactor = await ctx.context.adapter.findOne({
|
|
141
|
+
model: twoFactorTable,
|
|
142
|
+
where: [{
|
|
143
|
+
field: "userId",
|
|
144
|
+
value: user.id
|
|
145
|
+
}]
|
|
146
|
+
});
|
|
147
|
+
if (!twoFactor) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.TOTP_NOT_ENABLED);
|
|
148
|
+
if (isSignIn && twoFactor.verified === false) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.TOTP_NOT_ENABLED);
|
|
149
|
+
if (isSignIn) await assertTwoFactorNotLocked(ctx, twoFactorTable, twoFactor);
|
|
150
|
+
const attempt = isSignIn ? await beginAttempt(5) : null;
|
|
151
|
+
let status;
|
|
152
|
+
try {
|
|
153
|
+
const decrypted = await decryptTOTPSecret({
|
|
154
|
+
key: ctx.context.secretConfig,
|
|
155
|
+
data: twoFactor.secret
|
|
156
|
+
});
|
|
157
|
+
status = await createOTP(decrypted, {
|
|
158
|
+
period: opts.period,
|
|
159
|
+
digits: opts.digits
|
|
160
|
+
}).verify(ctx.body.code);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
await attempt?.restore();
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
if (!status) {
|
|
166
|
+
await attempt?.recordFailure();
|
|
167
|
+
if (isSignIn) await recordTwoFactorFailure(ctx, twoFactorTable, twoFactor);
|
|
168
|
+
return invalid("INVALID_CODE");
|
|
169
|
+
}
|
|
170
|
+
if (isSignIn) await resetTwoFactorFailures(ctx, twoFactorTable, twoFactor);
|
|
171
|
+
if (twoFactor.verified !== true) {
|
|
172
|
+
if (!user.twoFactorEnabled) {
|
|
173
|
+
const activeSession = session.session;
|
|
174
|
+
const updatedUser = await ctx.context.internalAdapter.updateUser(user.id, { twoFactorEnabled: true });
|
|
175
|
+
const newSession = await ctx.context.internalAdapter.createSession(user.id, false, activeSession);
|
|
176
|
+
await setSessionCookie(ctx, {
|
|
177
|
+
session: newSession,
|
|
178
|
+
user: updatedUser
|
|
179
|
+
});
|
|
180
|
+
await ctx.context.internalAdapter.deleteSession(activeSession.token);
|
|
181
|
+
}
|
|
182
|
+
await ctx.context.adapter.update({
|
|
183
|
+
model: twoFactorTable,
|
|
184
|
+
update: { verified: true },
|
|
185
|
+
where: [{
|
|
186
|
+
field: "id",
|
|
187
|
+
value: twoFactor.id
|
|
188
|
+
}]
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return valid(ctx);
|
|
192
|
+
});
|
|
32
193
|
return {
|
|
33
194
|
id: "totp",
|
|
34
195
|
version: PACKAGE_VERSION,
|
|
@@ -45,33 +206,7 @@ const totp2fa = (options) => {
|
|
|
45
206
|
*
|
|
46
207
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#totp)
|
|
47
208
|
*/
|
|
48
|
-
generateTOTP
|
|
49
|
-
method: "POST",
|
|
50
|
-
body: generateTOTPBodySchema,
|
|
51
|
-
metadata: { openapi: {
|
|
52
|
-
summary: "Generate TOTP code",
|
|
53
|
-
description: "Use this endpoint to generate a TOTP code",
|
|
54
|
-
responses: { 200: {
|
|
55
|
-
description: "Successful response",
|
|
56
|
-
content: { "application/json": { schema: {
|
|
57
|
-
type: "object",
|
|
58
|
-
properties: { code: { type: "string" } }
|
|
59
|
-
} } }
|
|
60
|
-
} }
|
|
61
|
-
} }
|
|
62
|
-
}, async (ctx) => {
|
|
63
|
-
if (options?.disable) {
|
|
64
|
-
ctx.context.logger.error("totp isn't configured. please pass totp option on two factor plugin to enable totp");
|
|
65
|
-
throw APIError.from("BAD_REQUEST", {
|
|
66
|
-
message: "totp isn't configured",
|
|
67
|
-
code: "TOTP_NOT_CONFIGURED"
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
return { code: await createOTP(ctx.body.secret, {
|
|
71
|
-
period: opts.period,
|
|
72
|
-
digits: opts.digits
|
|
73
|
-
}).totp() };
|
|
74
|
-
}),
|
|
209
|
+
generateTOTP,
|
|
75
210
|
/**
|
|
76
211
|
* ### Endpoint
|
|
77
212
|
*
|
|
@@ -87,51 +222,7 @@ const totp2fa = (options) => {
|
|
|
87
222
|
*
|
|
88
223
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#getting-totp-uri)
|
|
89
224
|
*/
|
|
90
|
-
getTOTPURI
|
|
91
|
-
method: "POST",
|
|
92
|
-
use: [sessionMiddleware],
|
|
93
|
-
body: getTOTPURIBodySchema,
|
|
94
|
-
metadata: { openapi: {
|
|
95
|
-
summary: "Get TOTP URI",
|
|
96
|
-
description: "Use this endpoint to get the TOTP URI",
|
|
97
|
-
responses: { 200: {
|
|
98
|
-
description: "Successful response",
|
|
99
|
-
content: { "application/json": { schema: {
|
|
100
|
-
type: "object",
|
|
101
|
-
properties: { totpURI: { type: "string" } }
|
|
102
|
-
} } }
|
|
103
|
-
} }
|
|
104
|
-
} }
|
|
105
|
-
}, async (ctx) => {
|
|
106
|
-
if (options?.disable) {
|
|
107
|
-
ctx.context.logger.error("totp isn't configured. please pass totp option on two factor plugin to enable totp");
|
|
108
|
-
throw APIError.from("BAD_REQUEST", {
|
|
109
|
-
message: "totp isn't configured",
|
|
110
|
-
code: "TOTP_NOT_CONFIGURED"
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
const user = ctx.context.session.user;
|
|
114
|
-
const twoFactor = await ctx.context.adapter.findOne({
|
|
115
|
-
model: twoFactorTable,
|
|
116
|
-
where: [{
|
|
117
|
-
field: "userId",
|
|
118
|
-
value: user.id
|
|
119
|
-
}]
|
|
120
|
-
});
|
|
121
|
-
if (!twoFactor) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.TOTP_NOT_ENABLED);
|
|
122
|
-
const secret = await symmetricDecrypt({
|
|
123
|
-
key: ctx.context.secretConfig,
|
|
124
|
-
data: twoFactor.secret
|
|
125
|
-
});
|
|
126
|
-
if (await shouldRequirePassword(ctx, user.id, options?.allowPasswordless)) {
|
|
127
|
-
if (!ctx.body.password) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.INVALID_PASSWORD);
|
|
128
|
-
await ctx.context.password.checkPassword(user.id, ctx);
|
|
129
|
-
}
|
|
130
|
-
return { totpURI: createOTP(secret, {
|
|
131
|
-
digits: opts.digits,
|
|
132
|
-
period: opts.period
|
|
133
|
-
}).url(options?.issuer || ctx.context.appName, user.email) };
|
|
134
|
-
}),
|
|
225
|
+
getTOTPURI,
|
|
135
226
|
/**
|
|
136
227
|
* ### Endpoint
|
|
137
228
|
*
|
|
@@ -147,82 +238,7 @@ const totp2fa = (options) => {
|
|
|
147
238
|
*
|
|
148
239
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/2fa#verifying-totp)
|
|
149
240
|
*/
|
|
150
|
-
verifyTOTP
|
|
151
|
-
method: "POST",
|
|
152
|
-
body: verifyTOTPBodySchema,
|
|
153
|
-
metadata: { openapi: {
|
|
154
|
-
summary: "Verify two factor TOTP",
|
|
155
|
-
description: "Verify two factor TOTP",
|
|
156
|
-
responses: { 200: {
|
|
157
|
-
description: "Successful response",
|
|
158
|
-
content: { "application/json": { schema: {
|
|
159
|
-
type: "object",
|
|
160
|
-
properties: { status: { type: "boolean" } }
|
|
161
|
-
} } }
|
|
162
|
-
} }
|
|
163
|
-
} }
|
|
164
|
-
}, async (ctx) => {
|
|
165
|
-
if (options?.disable) {
|
|
166
|
-
ctx.context.logger.error("totp isn't configured. please pass totp option on two factor plugin to enable totp");
|
|
167
|
-
throw APIError.from("BAD_REQUEST", {
|
|
168
|
-
message: "totp isn't configured",
|
|
169
|
-
code: "TOTP_NOT_CONFIGURED"
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
const { session, valid, invalid, beginAttempt } = await verifyTwoFactor(ctx);
|
|
173
|
-
const user = session.user;
|
|
174
|
-
const isSignIn = !session.session;
|
|
175
|
-
const twoFactor = await ctx.context.adapter.findOne({
|
|
176
|
-
model: twoFactorTable,
|
|
177
|
-
where: [{
|
|
178
|
-
field: "userId",
|
|
179
|
-
value: user.id
|
|
180
|
-
}]
|
|
181
|
-
});
|
|
182
|
-
if (!twoFactor) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.TOTP_NOT_ENABLED);
|
|
183
|
-
if (isSignIn && twoFactor.verified === false) throw APIError.from("BAD_REQUEST", TWO_FACTOR_ERROR_CODES.TOTP_NOT_ENABLED);
|
|
184
|
-
if (isSignIn) await assertTwoFactorNotLocked(ctx, twoFactorTable, twoFactor);
|
|
185
|
-
const attempt = isSignIn ? await beginAttempt(5) : null;
|
|
186
|
-
let status;
|
|
187
|
-
try {
|
|
188
|
-
status = await createOTP(await symmetricDecrypt({
|
|
189
|
-
key: ctx.context.secretConfig,
|
|
190
|
-
data: twoFactor.secret
|
|
191
|
-
}), {
|
|
192
|
-
period: opts.period,
|
|
193
|
-
digits: opts.digits
|
|
194
|
-
}).verify(ctx.body.code);
|
|
195
|
-
} catch (error) {
|
|
196
|
-
await attempt?.restore();
|
|
197
|
-
throw error;
|
|
198
|
-
}
|
|
199
|
-
if (!status) {
|
|
200
|
-
await attempt?.recordFailure();
|
|
201
|
-
if (isSignIn) await recordTwoFactorFailure(ctx, twoFactorTable, twoFactor);
|
|
202
|
-
return invalid("INVALID_CODE");
|
|
203
|
-
}
|
|
204
|
-
if (isSignIn) await resetTwoFactorFailures(ctx, twoFactorTable, twoFactor);
|
|
205
|
-
if (twoFactor.verified !== true) {
|
|
206
|
-
if (!user.twoFactorEnabled) {
|
|
207
|
-
const activeSession = session.session;
|
|
208
|
-
const updatedUser = await ctx.context.internalAdapter.updateUser(user.id, { twoFactorEnabled: true });
|
|
209
|
-
await setSessionCookie(ctx, {
|
|
210
|
-
session: await ctx.context.internalAdapter.createSession(user.id, false, activeSession),
|
|
211
|
-
user: updatedUser
|
|
212
|
-
});
|
|
213
|
-
await ctx.context.internalAdapter.deleteSession(activeSession.token);
|
|
214
|
-
}
|
|
215
|
-
await ctx.context.adapter.update({
|
|
216
|
-
model: twoFactorTable,
|
|
217
|
-
update: { verified: true },
|
|
218
|
-
where: [{
|
|
219
|
-
field: "id",
|
|
220
|
-
value: twoFactor.id
|
|
221
|
-
}]
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
return valid(ctx);
|
|
225
|
-
})
|
|
241
|
+
verifyTOTP
|
|
226
242
|
}
|
|
227
243
|
};
|
|
228
244
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { User } from "../../types/models.mjs";
|
|
2
2
|
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
3
|
+
import "../../types/index.mjs";
|
|
3
4
|
import { BackupCodeOptions } from "./backup-codes/index.mjs";
|
|
4
5
|
import { OTPOptions } from "./otp/index.mjs";
|
|
5
6
|
import { schema } from "./schema.mjs";
|
|
6
7
|
import { TOTPOptions } from "./totp/index.mjs";
|
|
7
8
|
import { BetterAuthPlugin, LiteralString } from "@better-auth/core";
|
|
8
|
-
|
|
9
9
|
//#region src/plugins/two-factor/types.d.ts
|
|
10
|
-
interface TwoFactorOptions {
|
|
10
|
+
export interface TwoFactorOptions {
|
|
11
11
|
/**
|
|
12
12
|
* Application Name
|
|
13
13
|
*/
|
|
@@ -87,18 +87,18 @@ interface TwoFactorOptions {
|
|
|
87
87
|
durationSeconds?: number | undefined;
|
|
88
88
|
} | undefined;
|
|
89
89
|
}
|
|
90
|
-
interface UserWithTwoFactor extends User {
|
|
90
|
+
export interface UserWithTwoFactor extends User {
|
|
91
91
|
/**
|
|
92
92
|
* If the user has enabled two factor authentication.
|
|
93
93
|
*/
|
|
94
94
|
twoFactorEnabled: boolean;
|
|
95
95
|
}
|
|
96
|
-
interface TwoFactorProvider {
|
|
96
|
+
export interface TwoFactorProvider {
|
|
97
97
|
id: LiteralString;
|
|
98
98
|
version?: string | undefined;
|
|
99
99
|
endpoints?: BetterAuthPlugin["endpoints"] | undefined;
|
|
100
100
|
}
|
|
101
|
-
interface TwoFactorTable {
|
|
101
|
+
export interface TwoFactorTable {
|
|
102
102
|
id: string;
|
|
103
103
|
userId: string;
|
|
104
104
|
secret: string;
|
|
@@ -107,5 +107,4 @@ interface TwoFactorTable {
|
|
|
107
107
|
failedVerificationCount?: number;
|
|
108
108
|
lockedUntil?: Date | null;
|
|
109
109
|
}
|
|
110
|
-
//#endregion
|
|
111
|
-
export { TwoFactorOptions, TwoFactorProvider, TwoFactorTable, UserWithTwoFactor };
|
|
110
|
+
//#endregion
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { USERNAME_ERROR_CODES } from "./error-codes.mjs";
|
|
2
2
|
import { UsernamePlugin, UsernamePluginWithoutDisplayUsername } from "./index.mjs";
|
|
3
|
-
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/username/client.d.ts
|
|
6
|
-
type UsernameClientOptions = {
|
|
4
|
+
export type UsernameClientOptions = {
|
|
7
5
|
/**
|
|
8
6
|
* Whether the server has the `displayUsername` field enabled.
|
|
9
7
|
*
|
|
@@ -14,7 +12,7 @@ type UsernameClientOptions = {
|
|
|
14
12
|
*/
|
|
15
13
|
displayUsername?: boolean | undefined;
|
|
16
14
|
};
|
|
17
|
-
declare const usernameClient: <O extends UsernameClientOptions = UsernameClientOptions>(options?: O) => {
|
|
15
|
+
export declare const usernameClient: <O extends UsernameClientOptions = UsernameClientOptions>(options?: O) => {
|
|
18
16
|
id: "username";
|
|
19
17
|
version: string;
|
|
20
18
|
$InferServerPlugin: O["displayUsername"] extends false ? UsernamePluginWithoutDisplayUsername : UsernamePlugin;
|
|
@@ -23,16 +21,16 @@ declare const usernameClient: <O extends UsernameClientOptions = UsernameClientO
|
|
|
23
21
|
signal: "$sessionSignal";
|
|
24
22
|
}[];
|
|
25
23
|
$ERROR_CODES: {
|
|
26
|
-
EMAIL_NOT_VERIFIED:
|
|
27
|
-
UNEXPECTED_ERROR:
|
|
28
|
-
INVALID_USERNAME_OR_PASSWORD:
|
|
29
|
-
USERNAME_IS_ALREADY_TAKEN:
|
|
30
|
-
USERNAME_TOO_SHORT:
|
|
31
|
-
USERNAME_TOO_LONG:
|
|
32
|
-
INVALID_USERNAME:
|
|
33
|
-
INVALID_DISPLAY_USERNAME:
|
|
34
|
-
USERNAME_IS_IMMUTABLE:
|
|
24
|
+
EMAIL_NOT_VERIFIED: import("@better-auth/core/utils/error-codes").RawError<"EMAIL_NOT_VERIFIED">;
|
|
25
|
+
UNEXPECTED_ERROR: import("@better-auth/core/utils/error-codes").RawError<"UNEXPECTED_ERROR">;
|
|
26
|
+
INVALID_USERNAME_OR_PASSWORD: import("@better-auth/core/utils/error-codes").RawError<"INVALID_USERNAME_OR_PASSWORD">;
|
|
27
|
+
USERNAME_IS_ALREADY_TAKEN: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_IS_ALREADY_TAKEN">;
|
|
28
|
+
USERNAME_TOO_SHORT: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_TOO_SHORT">;
|
|
29
|
+
USERNAME_TOO_LONG: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_TOO_LONG">;
|
|
30
|
+
INVALID_USERNAME: import("@better-auth/core/utils/error-codes").RawError<"INVALID_USERNAME">;
|
|
31
|
+
INVALID_DISPLAY_USERNAME: import("@better-auth/core/utils/error-codes").RawError<"INVALID_DISPLAY_USERNAME">;
|
|
32
|
+
USERNAME_IS_IMMUTABLE: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_IS_IMMUTABLE">;
|
|
35
33
|
};
|
|
36
34
|
};
|
|
37
35
|
//#endregion
|
|
38
|
-
export {
|
|
36
|
+
export { USERNAME_ERROR_CODES };
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
2
|
-
|
|
3
1
|
//#region src/plugins/username/error-codes.d.ts
|
|
4
|
-
declare const USERNAME_ERROR_CODES: {
|
|
5
|
-
EMAIL_NOT_VERIFIED:
|
|
6
|
-
UNEXPECTED_ERROR:
|
|
7
|
-
INVALID_USERNAME_OR_PASSWORD:
|
|
8
|
-
USERNAME_IS_ALREADY_TAKEN:
|
|
9
|
-
USERNAME_TOO_SHORT:
|
|
10
|
-
USERNAME_TOO_LONG:
|
|
11
|
-
INVALID_USERNAME:
|
|
12
|
-
INVALID_DISPLAY_USERNAME:
|
|
13
|
-
USERNAME_IS_IMMUTABLE:
|
|
2
|
+
export declare const USERNAME_ERROR_CODES: {
|
|
3
|
+
EMAIL_NOT_VERIFIED: import("@better-auth/core/utils/error-codes").RawError<"EMAIL_NOT_VERIFIED">;
|
|
4
|
+
UNEXPECTED_ERROR: import("@better-auth/core/utils/error-codes").RawError<"UNEXPECTED_ERROR">;
|
|
5
|
+
INVALID_USERNAME_OR_PASSWORD: import("@better-auth/core/utils/error-codes").RawError<"INVALID_USERNAME_OR_PASSWORD">;
|
|
6
|
+
USERNAME_IS_ALREADY_TAKEN: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_IS_ALREADY_TAKEN">;
|
|
7
|
+
USERNAME_TOO_SHORT: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_TOO_SHORT">;
|
|
8
|
+
USERNAME_TOO_LONG: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_TOO_LONG">;
|
|
9
|
+
INVALID_USERNAME: import("@better-auth/core/utils/error-codes").RawError<"INVALID_USERNAME">;
|
|
10
|
+
INVALID_DISPLAY_USERNAME: import("@better-auth/core/utils/error-codes").RawError<"INVALID_DISPLAY_USERNAME">;
|
|
11
|
+
USERNAME_IS_IMMUTABLE: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_IS_IMMUTABLE">;
|
|
14
12
|
};
|
|
15
|
-
//#endregion
|
|
16
|
-
export { USERNAME_ERROR_CODES };
|
|
13
|
+
//#endregion
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
2
2
|
import { UsernameSchema } from "./schema.mjs";
|
|
3
3
|
import { USERNAME_ERROR_CODES } from "./error-codes.mjs";
|
|
4
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
5
|
-
import * as _$_better_auth_core_db0 from "@better-auth/core/db";
|
|
6
|
-
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
7
|
-
import * as _$better_call0 from "better-call";
|
|
8
4
|
import * as z from "zod";
|
|
9
|
-
|
|
10
5
|
//#region src/plugins/username/index.d.ts
|
|
11
6
|
declare module "@better-auth/core" {
|
|
12
7
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -15,7 +10,7 @@ declare module "@better-auth/core" {
|
|
|
15
10
|
};
|
|
16
11
|
}
|
|
17
12
|
}
|
|
18
|
-
type UsernameOptions = {
|
|
13
|
+
export type UsernameOptions = {
|
|
19
14
|
schema?: InferOptionSchema<UsernameSchema> | undefined;
|
|
20
15
|
/**
|
|
21
16
|
* The minimum length of the username
|
|
@@ -93,7 +88,7 @@ type UsernameOptions = {
|
|
|
93
88
|
declare const usernameImpl: <IncludeDisplayUsername extends boolean>(options: UsernameOptions | undefined, includeDisplayUsername: IncludeDisplayUsername) => {
|
|
94
89
|
id: "username";
|
|
95
90
|
version: string;
|
|
96
|
-
init(ctx:
|
|
91
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
97
92
|
options: {
|
|
98
93
|
databaseHooks: {
|
|
99
94
|
user: {
|
|
@@ -106,7 +101,7 @@ declare const usernameImpl: <IncludeDisplayUsername extends boolean>(options: Us
|
|
|
106
101
|
emailVerified: boolean;
|
|
107
102
|
name: string;
|
|
108
103
|
image?: string | null | undefined;
|
|
109
|
-
} & Record<string, unknown>, context:
|
|
104
|
+
} & Record<string, unknown>, context: import("@better-auth/core").GenericEndpointContext | null): Promise<{
|
|
110
105
|
data: {
|
|
111
106
|
displayUsername?: string | undefined;
|
|
112
107
|
username: string;
|
|
@@ -140,7 +135,7 @@ declare const usernameImpl: <IncludeDisplayUsername extends boolean>(options: Us
|
|
|
140
135
|
emailVerified: boolean;
|
|
141
136
|
name: string;
|
|
142
137
|
image?: string | null | undefined;
|
|
143
|
-
}> & Record<string, unknown>, context:
|
|
138
|
+
}> & Record<string, unknown>, context: import("@better-auth/core").GenericEndpointContext | null): Promise<{
|
|
144
139
|
data: {
|
|
145
140
|
displayUsername?: string | undefined;
|
|
146
141
|
username: string;
|
|
@@ -170,7 +165,7 @@ declare const usernameImpl: <IncludeDisplayUsername extends boolean>(options: Us
|
|
|
170
165
|
};
|
|
171
166
|
};
|
|
172
167
|
endpoints: {
|
|
173
|
-
signInUsername:
|
|
168
|
+
signInUsername: import("better-call").StrictEndpoint<"/sign-in/username", {
|
|
174
169
|
method: "POST";
|
|
175
170
|
body: z.ZodObject<{
|
|
176
171
|
username: z.ZodString;
|
|
@@ -247,7 +242,7 @@ declare const usernameImpl: <IncludeDisplayUsername extends boolean>(options: Us
|
|
|
247
242
|
displayUsername: string;
|
|
248
243
|
};
|
|
249
244
|
}>;
|
|
250
|
-
isUsernameAvailable:
|
|
245
|
+
isUsernameAvailable: import("better-call").StrictEndpoint<"/is-username-available", {
|
|
251
246
|
method: "POST";
|
|
252
247
|
body: z.ZodObject<{
|
|
253
248
|
username: z.ZodString;
|
|
@@ -266,14 +261,14 @@ declare const usernameImpl: <IncludeDisplayUsername extends boolean>(options: Us
|
|
|
266
261
|
unique: true;
|
|
267
262
|
returned: true;
|
|
268
263
|
transform: {
|
|
269
|
-
input(value:
|
|
264
|
+
input(value: import("@better-auth/core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
270
265
|
};
|
|
271
266
|
};
|
|
272
267
|
displayUsername: {
|
|
273
268
|
type: "string";
|
|
274
269
|
required: false;
|
|
275
270
|
transform: {
|
|
276
|
-
input(value:
|
|
271
|
+
input(value: import("@better-auth/core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
277
272
|
};
|
|
278
273
|
};
|
|
279
274
|
}, "username"> : {
|
|
@@ -284,14 +279,14 @@ declare const usernameImpl: <IncludeDisplayUsername extends boolean>(options: Us
|
|
|
284
279
|
unique: true;
|
|
285
280
|
returned: true;
|
|
286
281
|
transform: {
|
|
287
|
-
input(value:
|
|
282
|
+
input(value: import("@better-auth/core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
288
283
|
};
|
|
289
284
|
};
|
|
290
285
|
displayUsername: {
|
|
291
286
|
type: "string";
|
|
292
287
|
required: false;
|
|
293
288
|
transform: {
|
|
294
|
-
input(value:
|
|
289
|
+
input(value: import("@better-auth/core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
295
290
|
};
|
|
296
291
|
};
|
|
297
292
|
};
|
|
@@ -299,28 +294,28 @@ declare const usernameImpl: <IncludeDisplayUsername extends boolean>(options: Us
|
|
|
299
294
|
};
|
|
300
295
|
hooks: {
|
|
301
296
|
before: {
|
|
302
|
-
matcher(context:
|
|
303
|
-
handler:
|
|
297
|
+
matcher(context: import("@better-auth/core").HookEndpointContext): boolean;
|
|
298
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
304
299
|
}[];
|
|
305
300
|
};
|
|
306
301
|
options: UsernameOptions | undefined;
|
|
307
302
|
$ERROR_CODES: {
|
|
308
|
-
EMAIL_NOT_VERIFIED:
|
|
309
|
-
UNEXPECTED_ERROR:
|
|
310
|
-
INVALID_USERNAME_OR_PASSWORD:
|
|
311
|
-
USERNAME_IS_ALREADY_TAKEN:
|
|
312
|
-
USERNAME_TOO_SHORT:
|
|
313
|
-
USERNAME_TOO_LONG:
|
|
314
|
-
INVALID_USERNAME:
|
|
315
|
-
INVALID_DISPLAY_USERNAME:
|
|
316
|
-
USERNAME_IS_IMMUTABLE:
|
|
303
|
+
EMAIL_NOT_VERIFIED: import("@better-auth/core/utils/error-codes").RawError<"EMAIL_NOT_VERIFIED">;
|
|
304
|
+
UNEXPECTED_ERROR: import("@better-auth/core/utils/error-codes").RawError<"UNEXPECTED_ERROR">;
|
|
305
|
+
INVALID_USERNAME_OR_PASSWORD: import("@better-auth/core/utils/error-codes").RawError<"INVALID_USERNAME_OR_PASSWORD">;
|
|
306
|
+
USERNAME_IS_ALREADY_TAKEN: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_IS_ALREADY_TAKEN">;
|
|
307
|
+
USERNAME_TOO_SHORT: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_TOO_SHORT">;
|
|
308
|
+
USERNAME_TOO_LONG: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_TOO_LONG">;
|
|
309
|
+
INVALID_USERNAME: import("@better-auth/core/utils/error-codes").RawError<"INVALID_USERNAME">;
|
|
310
|
+
INVALID_DISPLAY_USERNAME: import("@better-auth/core/utils/error-codes").RawError<"INVALID_DISPLAY_USERNAME">;
|
|
311
|
+
USERNAME_IS_IMMUTABLE: import("@better-auth/core/utils/error-codes").RawError<"USERNAME_IS_IMMUTABLE">;
|
|
317
312
|
};
|
|
318
313
|
};
|
|
319
|
-
type UsernamePlugin = ReturnType<typeof usernameImpl<true>>;
|
|
320
|
-
type UsernamePluginWithoutDisplayUsername = ReturnType<typeof usernameImpl<false>>;
|
|
321
|
-
declare function username(options: UsernameOptions & {
|
|
314
|
+
export type UsernamePlugin = ReturnType<typeof usernameImpl<true>>;
|
|
315
|
+
export type UsernamePluginWithoutDisplayUsername = ReturnType<typeof usernameImpl<false>>;
|
|
316
|
+
export declare function username(options: UsernameOptions & {
|
|
322
317
|
displayUsername: false;
|
|
323
318
|
}): UsernamePluginWithoutDisplayUsername;
|
|
324
|
-
declare function username(options?: UsernameOptions): UsernamePlugin;
|
|
319
|
+
export declare function username(options?: UsernameOptions): UsernamePlugin;
|
|
325
320
|
//#endregion
|
|
326
|
-
export { USERNAME_ERROR_CODES
|
|
321
|
+
export { USERNAME_ERROR_CODES };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as _$_better_auth_core_db0 from "@better-auth/core/db";
|
|
2
|
-
|
|
3
1
|
//#region src/plugins/username/schema.d.ts
|
|
4
|
-
declare const getSchema: <IncludeDisplayUsername extends boolean = true>(normalizer: {
|
|
2
|
+
export declare const getSchema: <IncludeDisplayUsername extends boolean = true>(normalizer: {
|
|
5
3
|
username: (username: string) => string;
|
|
6
4
|
displayUsername: (displayUsername: string) => string;
|
|
7
5
|
}, includeDisplayUsername?: IncludeDisplayUsername) => {
|
|
@@ -14,14 +12,14 @@ declare const getSchema: <IncludeDisplayUsername extends boolean = true>(normali
|
|
|
14
12
|
unique: true;
|
|
15
13
|
returned: true;
|
|
16
14
|
transform: {
|
|
17
|
-
input(value:
|
|
15
|
+
input(value: import("@better-auth/core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
18
16
|
};
|
|
19
17
|
};
|
|
20
18
|
displayUsername: {
|
|
21
19
|
type: "string";
|
|
22
20
|
required: false;
|
|
23
21
|
transform: {
|
|
24
|
-
input(value:
|
|
22
|
+
input(value: import("@better-auth/core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
25
23
|
};
|
|
26
24
|
};
|
|
27
25
|
}, "username"> : {
|
|
@@ -32,19 +30,18 @@ declare const getSchema: <IncludeDisplayUsername extends boolean = true>(normali
|
|
|
32
30
|
unique: true;
|
|
33
31
|
returned: true;
|
|
34
32
|
transform: {
|
|
35
|
-
input(value:
|
|
33
|
+
input(value: import("@better-auth/core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
36
34
|
};
|
|
37
35
|
};
|
|
38
36
|
displayUsername: {
|
|
39
37
|
type: "string";
|
|
40
38
|
required: false;
|
|
41
39
|
transform: {
|
|
42
|
-
input(value:
|
|
40
|
+
input(value: import("@better-auth/core/db").DBPrimitive): string | number | boolean | Date | unknown[] | Record<string, unknown> | null | undefined;
|
|
43
41
|
};
|
|
44
42
|
};
|
|
45
43
|
};
|
|
46
44
|
};
|
|
47
45
|
};
|
|
48
|
-
type UsernameSchema = ReturnType<typeof getSchema<true>>;
|
|
49
|
-
//#endregion
|
|
50
|
-
export { UsernameSchema };
|
|
46
|
+
export type UsernameSchema = ReturnType<typeof getSchema<true>>;
|
|
47
|
+
//#endregion
|