@better-auth-ui/react 1.6.27 → 1.6.29

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.
@@ -1,11 +1,14 @@
1
1
  import { apiKeyClient } from '@better-auth/api-key/client';
2
2
  import { passkeyClient } from '@better-auth/passkey/client';
3
- import { magicLinkClient, multiSessionClient, organizationClient, usernameClient } from 'better-auth/client/plugins';
3
+ import { lastLoginMethodClient, magicLinkClient, multiSessionClient, organizationClient, usernameClient } from 'better-auth/client/plugins';
4
4
  import { createAuthClient } from 'better-auth/react';
5
5
  export type AuthClient = ReturnType<typeof createAuthClient>;
6
6
  export type MagicLinkAuthClient = ReturnType<typeof createAuthClient<{
7
7
  plugins: [ReturnType<typeof magicLinkClient>];
8
8
  }>>;
9
+ export type LastLoginMethodAuthClient = ReturnType<typeof createAuthClient<{
10
+ plugins: [ReturnType<typeof lastLoginMethodClient>];
11
+ }>>;
9
12
  export type MultiSessionAuthClient = ReturnType<typeof createAuthClient<{
10
13
  plugins: [ReturnType<typeof multiSessionClient>];
11
14
  }>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth-ui/react",
3
- "version": "1.6.27",
3
+ "version": "1.6.29",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -38,8 +38,7 @@
38
38
  "devDependencies": {
39
39
  "@better-auth/api-key": "^1.6.19",
40
40
  "@better-auth/passkey": "^1.6.19",
41
- "@react-email/components": "^1.0.12",
42
- "@react-email/preview-server": "^5.2.10",
41
+ "@react-email/ui": "6.6.8",
43
42
  "@tanstack/query-core": "^5.100.14",
44
43
  "@tanstack/react-query": "^5.100.14",
45
44
  "@testing-library/react": "^16.3.2",
@@ -52,7 +51,7 @@
52
51
  "playwright": "^1.61.0",
53
52
  "react": "^19.2.6",
54
53
  "react-dom": "^19.2.6",
55
- "react-email": "^6.6.3",
54
+ "react-email": "^6.6.8",
56
55
  "tailwind-merge": "^3.5.0",
57
56
  "tailwindcss": "^4.3.1",
58
57
  "vitest": "^4.1.9",
@@ -62,17 +61,22 @@
62
61
  "@better-auth-ui/core": "*",
63
62
  "@better-auth/api-key": ">=1.6.19",
64
63
  "@better-auth/passkey": ">=1.6.19",
65
- "@react-email/components": ">=1.0.12",
66
64
  "@tanstack/query-core": ">=5.100.14",
67
65
  "@tanstack/react-query": ">=5.100.14",
68
66
  "better-auth": ">=1.6.19",
69
67
  "clsx": ">=2.0.0",
70
68
  "react": ">=19.2.6",
71
69
  "react-dom": ">=19.2.6",
70
+ "react-email": ">=6.0.0",
72
71
  "tailwind-merge": ">=3.5.0",
73
72
  "tailwindcss": ">=4.3.1",
74
73
  "zod": ">=4.4.3"
75
74
  },
75
+ "peerDependenciesMeta": {
76
+ "react-email": {
77
+ "optional": true
78
+ }
79
+ },
76
80
  "repository": {
77
81
  "type": "git",
78
82
  "url": "https://github.com/better-auth-ui/better-auth-ui",
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react"
1
2
  import {
2
3
  Body,
3
4
  Button,
@@ -13,8 +14,7 @@ import {
13
14
  Section,
14
15
  Tailwind,
15
16
  Text
16
- } from "@react-email/components"
17
- import type { ReactNode } from "react"
17
+ } from "react-email"
18
18
 
19
19
  import { cn } from "../../../lib/utils"
20
20
  import {
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react"
1
2
  import {
2
3
  Body,
3
4
  Button,
@@ -13,8 +14,7 @@ import {
13
14
  Section,
14
15
  Tailwind,
15
16
  Text
16
- } from "@react-email/components"
17
- import type { ReactNode } from "react"
17
+ } from "react-email"
18
18
 
19
19
  import { cn } from "../../../lib/utils"
20
20
  import {
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react"
1
2
  import {
2
3
  Body,
3
4
  Button,
@@ -13,8 +14,7 @@ import {
13
14
  Section,
14
15
  Tailwind,
15
16
  Text
16
- } from "@react-email/components"
17
- import type { ReactNode } from "react"
17
+ } from "react-email"
18
18
 
19
19
  import { cn } from "../../../lib/utils"
20
20
  import {
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react"
1
2
  import {
2
3
  Body,
3
4
  Button,
@@ -13,8 +14,7 @@ import {
13
14
  Section,
14
15
  Tailwind,
15
16
  Text
16
- } from "@react-email/components"
17
- import type { ReactNode } from "react"
17
+ } from "react-email"
18
18
 
19
19
  import { cn } from "../../../lib/utils"
20
20
  import {
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react"
1
2
  import {
2
3
  Body,
3
4
  Button,
@@ -13,8 +14,7 @@ import {
13
14
  Section,
14
15
  Tailwind,
15
16
  Text
16
- } from "@react-email/components"
17
- import type { ReactNode } from "react"
17
+ } from "react-email"
18
18
 
19
19
  import { cn } from "../../../lib/utils"
20
20
  import {
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react"
1
2
  import {
2
3
  Body,
3
4
  Container,
@@ -12,8 +13,7 @@ import {
12
13
  Section,
13
14
  Tailwind,
14
15
  Text
15
- } from "@react-email/components"
16
- import type { ReactNode } from "react"
16
+ } from "react-email"
17
17
 
18
18
  import { cn } from "../../../lib/utils"
19
19
  import {
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react"
1
2
  import {
2
3
  Body,
3
4
  Button,
@@ -13,8 +14,7 @@ import {
13
14
  Section,
14
15
  Tailwind,
15
16
  Text
16
- } from "@react-email/components"
17
- import type { ReactNode } from "react"
17
+ } from "react-email"
18
18
 
19
19
  import { cn } from "../../../lib/utils"
20
20
  import {
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react"
1
2
  import {
2
3
  Body,
3
4
  Button,
@@ -13,8 +14,7 @@ import {
13
14
  Section,
14
15
  Tailwind,
15
16
  Text
16
- } from "@react-email/components"
17
- import type { ReactNode } from "react"
17
+ } from "react-email"
18
18
 
19
19
  import { cn } from "../../../lib/utils"
20
20
  import {
@@ -0,0 +1,51 @@
1
+ "use client"
2
+
3
+ import {
4
+ type LastLoginMethodLocalization,
5
+ lastLoginMethodLocalization,
6
+ lastLoginMethodPlugin
7
+ } from "@better-auth-ui/core/plugins"
8
+ import { useCallback, useSyncExternalStore } from "react"
9
+ import { useAuth } from "../../components/auth/auth-provider"
10
+ import type { LastLoginMethodAuthClient } from "../../lib/auth-client"
11
+
12
+ const subscribe = () => () => {}
13
+ const getServerSnapshot = () => null
14
+
15
+ export type LastLoginMethodState = {
16
+ /** Most recently used method, such as `"email"`, `"google"`, or `"github"`. */
17
+ method: string | null
18
+ /** Localization contributed by `lastLoginMethodPlugin()`. */
19
+ localization: LastLoginMethodLocalization
20
+ }
21
+
22
+ /**
23
+ * Reads Better Auth's last-login-method cookie after hydration.
24
+ *
25
+ * Always returns an object containing `method` and `localization`. Only
26
+ * `method` is `null` when the UI plugin is not registered or the matching
27
+ * Better Auth client plugin has no stored method.
28
+ */
29
+ export function useLastLoginMethod(): LastLoginMethodState {
30
+ const { authClient, plugins } = useAuth()
31
+ const plugin = plugins.find(
32
+ (candidate) => candidate.id === lastLoginMethodPlugin.id
33
+ )
34
+ const localization = {
35
+ ...lastLoginMethodLocalization,
36
+ ...(plugin?.localization as
37
+ | Partial<LastLoginMethodLocalization>
38
+ | undefined)
39
+ }
40
+
41
+ const getSnapshot = useCallback(() => {
42
+ if (!plugin) return null
43
+
44
+ const client = authClient as Partial<LastLoginMethodAuthClient>
45
+ return client.getLastUsedLoginMethod?.() ?? null
46
+ }, [authClient, plugin])
47
+
48
+ const method = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)
49
+
50
+ return { method, localization }
51
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./components/auth/fetch-options-provider"
5
5
  export * from "./components/icons"
6
6
  export * from "./components/settings/account/theme-preview"
7
7
  export * from "./hooks/auth/use-authenticate"
8
+ export * from "./hooks/auth/use-last-login-method"
8
9
  export * from "./hooks/auth/use-user"
9
10
  export * from "./hooks/use-auth-mutation"
10
11
  export * from "./hooks/use-auth-plugin"
@@ -1,6 +1,7 @@
1
1
  import type { apiKeyClient } from "@better-auth/api-key/client"
2
2
  import type { passkeyClient } from "@better-auth/passkey/client"
3
3
  import type {
4
+ lastLoginMethodClient,
4
5
  magicLinkClient,
5
6
  multiSessionClient,
6
7
  organizationClient,
@@ -20,6 +21,12 @@ export type MagicLinkAuthClient = ReturnType<
20
21
  typeof createAuthClient<{ plugins: [ReturnType<typeof magicLinkClient>] }>
21
22
  >
22
23
 
24
+ export type LastLoginMethodAuthClient = ReturnType<
25
+ typeof createAuthClient<{
26
+ plugins: [ReturnType<typeof lastLoginMethodClient>]
27
+ }>
28
+ >
29
+
23
30
  export type MultiSessionAuthClient = ReturnType<
24
31
  typeof createAuthClient<{ plugins: [ReturnType<typeof multiSessionClient>] }>
25
32
  >