From 6ef5104b1369a5b8602df4ff433fd10391cd1e33 Mon Sep 17 00:00:00 2001 From: matt <52623452+occorune@users.noreply.github.com> Date: Mon, 7 Jul 2025 20:53:17 +0100 Subject: [PATCH 1/4] fix(two-factor): getting totp uri shouldn't require twoFactor enabled (#2620) --- packages/better-auth/src/plugins/two-factor/totp/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/better-auth/src/plugins/two-factor/totp/index.ts b/packages/better-auth/src/plugins/two-factor/totp/index.ts index 5a7974780e..f1ba9bfd55 100644 --- a/packages/better-auth/src/plugins/two-factor/totp/index.ts +++ b/packages/better-auth/src/plugins/two-factor/totp/index.ts @@ -154,7 +154,7 @@ export const totp2fa = (options?: TOTPOptions) => { }, ], }); - if (!twoFactor || !user.twoFactorEnabled) { + if (!twoFactor) { throw new APIError("BAD_REQUEST", { message: TWO_FACTOR_ERROR_CODES.TOTP_NOT_ENABLED, }); From ba5f13c58a437bb6d4b544610eea05977cca4d79 Mon Sep 17 00:00:00 2001 From: KinfeMichael Tariku <65047246+Kinfe123@users.noreply.github.com> Date: Mon, 7 Jul 2025 12:54:26 -0700 Subject: [PATCH 2/4] fix(expo): expo plugin should import types from the types path (#2526) * fix: plugin import type * lint * expo type compat * expo type compat * type import * plugin import * type compat --- packages/expo/src/client.ts | 2 +- packages/expo/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/expo/src/client.ts b/packages/expo/src/client.ts index a0c72a89f0..0525a9f0b5 100644 --- a/packages/expo/src/client.ts +++ b/packages/expo/src/client.ts @@ -1,4 +1,4 @@ -import type { BetterAuthClientPlugin, Store } from "better-auth"; +import { BetterAuthClientPlugin, Store } from "better-auth/types"; import * as Browser from "expo-web-browser"; import * as Linking from "expo-linking"; import { Platform } from "react-native"; diff --git a/packages/expo/src/index.ts b/packages/expo/src/index.ts index 79f364f8ce..1cbcbe8fd2 100644 --- a/packages/expo/src/index.ts +++ b/packages/expo/src/index.ts @@ -1,4 +1,4 @@ -import type { BetterAuthPlugin } from "better-auth"; +import type { BetterAuthPlugin } from "better-auth/types"; import { createAuthMiddleware } from "better-auth/api"; export interface ExpoOptions { From 5e36e37d730af5898a2f06e11be1343443825efb Mon Sep 17 00:00:00 2001 From: KinfeMichael Tariku <65047246+Kinfe123@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:03:04 -0700 Subject: [PATCH 3/4] chore: export options on the plugin (#2681) * docs: typo in admin plugin * fix: export options * fix * import * import * lint * import * lint * fix: cast options to any --------- Co-authored-by: Bereket Engida --- packages/better-auth/src/plugins/admin/admin.ts | 1 + packages/better-auth/src/plugins/organization/organization.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/better-auth/src/plugins/admin/admin.ts b/packages/better-auth/src/plugins/admin/admin.ts index 3a17437ce1..f3eaeee9e7 100644 --- a/packages/better-auth/src/plugins/admin/admin.ts +++ b/packages/better-auth/src/plugins/admin/admin.ts @@ -1380,6 +1380,7 @@ export const admin = (options?: O) => { }, $ERROR_CODES: ADMIN_ERROR_CODES, schema: mergeSchema(schema, opts.schema), + options: options as any, } satisfies BetterAuthPlugin; }; diff --git a/packages/better-auth/src/plugins/organization/organization.ts b/packages/better-auth/src/plugins/organization/organization.ts index 406fbce45b..4197d9c633 100644 --- a/packages/better-auth/src/plugins/organization/organization.ts +++ b/packages/better-auth/src/plugins/organization/organization.ts @@ -752,5 +752,6 @@ export const organization = (options?: O) => { >, }, $ERROR_CODES: ORGANIZATION_ERROR_CODES, + options: options as any, } satisfies BetterAuthPlugin; }; From c483fa14db62b3a8d82049a167f9933c0542af7d Mon Sep 17 00:00:00 2001 From: KinfeMichael Tariku <65047246+Kinfe123@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:10:13 -0700 Subject: [PATCH 4/4] fix(two-factor): otp separator mismatch (#2989) * fix: otp value and tries separator * Update packages/better-auth/src/plugins/two-factor/otp/index.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * lint --------- Co-authored-by: Bereket Engida <86073083+Bekacru@users.noreply.github.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- packages/better-auth/src/plugins/two-factor/otp/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/better-auth/src/plugins/two-factor/otp/index.ts b/packages/better-auth/src/plugins/two-factor/otp/index.ts index 0141aa54af..21fb62a519 100644 --- a/packages/better-auth/src/plugins/two-factor/otp/index.ts +++ b/packages/better-auth/src/plugins/two-factor/otp/index.ts @@ -136,7 +136,7 @@ export const otp2fa = (options?: OTPOptions) => { const code = generateRandomString(opts.digits, "0-9"); await ctx.context.internalAdapter.createVerificationValue( { - value: `${code}!0`, + value: `${code}:0`, identifier: `2fa-otp-${key}`, expiresAt: new Date(Date.now() + opts.period), }, @@ -256,7 +256,7 @@ export const otp2fa = (options?: OTPOptions) => { await ctx.context.internalAdapter.findVerificationValue( `2fa-otp-${key}`, ); - const [otp, counter] = toCheckOtp?.value?.split("!") ?? []; + const [otp, counter] = toCheckOtp?.value?.split(":") ?? []; if (!toCheckOtp || toCheckOtp.expiresAt < new Date()) { if (toCheckOtp) { await ctx.context.internalAdapter.deleteVerificationValue( @@ -320,7 +320,7 @@ export const otp2fa = (options?: OTPOptions) => { await ctx.context.internalAdapter.updateVerificationValue( toCheckOtp.id, { - value: `${otp}!${parseInt(counter) + 1}`, + value: `${otp}:${(parseInt(counter, 10) || 0) + 1}`, }, ); return invalid("INVALID_CODE");