better-auth-ui 3.2.5
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/auth-hooks-IOEvlYYv.d.cts +6966 -0
- package/dist/auth-hooks-IOEvlYYv.d.ts +6966 -0
- package/dist/auth-mutators-DdqOmQ32.d.cts +29 -0
- package/dist/auth-mutators-DdqOmQ32.d.ts +29 -0
- package/dist/auth-ui-provider-BsH3xJDw.d.ts +697 -0
- package/dist/auth-ui-provider-DhZfncd3.d.cts +697 -0
- package/dist/chunk-BDFQSFBU.js +750 -0
- package/dist/chunk-CRAHKL2C.cjs +801 -0
- package/dist/chunk-MJPOA6PK.js +801 -0
- package/dist/chunk-SV64DXGW.cjs +750 -0
- package/dist/index.cjs +12618 -0
- package/dist/index.d.cts +771 -0
- package/dist/index.d.ts +771 -0
- package/dist/index.js +12618 -0
- package/dist/instantdb.cjs +189 -0
- package/dist/instantdb.d.cts +36 -0
- package/dist/instantdb.d.ts +36 -0
- package/dist/instantdb.js +189 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/server.cjs +194 -0
- package/dist/server.d.cts +35 -0
- package/dist/server.d.ts +35 -0
- package/dist/server.js +194 -0
- package/dist/style.css +1 -0
- package/dist/tanstack.cjs +153 -0
- package/dist/tanstack.d.cts +18 -0
- package/dist/tanstack.d.ts +18 -0
- package/dist/tanstack.js +153 -0
- package/dist/triplit.cjs +201 -0
- package/dist/triplit.d.cts +31 -0
- package/dist/triplit.d.ts +31 -0
- package/dist/triplit.js +201 -0
- package/dist/utils-C5R37WDe.d.cts +3 -0
- package/dist/utils-C5R37WDe.d.ts +3 -0
- package/dist/view-paths-CHSJf5dv.d.cts +645 -0
- package/dist/view-paths-CHSJf5dv.d.ts +645 -0
- package/package.json +156 -0
- package/src/components/account/account-view.tsx +220 -0
- package/src/components/auth/auth-callback.tsx +36 -0
- package/src/components/auth/auth-form.tsx +277 -0
- package/src/components/auth/auth-view.tsx +389 -0
- package/src/components/auth/email-otp-button.tsx +53 -0
- package/src/components/auth/forms/email-otp-form.tsx +288 -0
- package/src/components/auth/forms/forgot-password-form.tsx +168 -0
- package/src/components/auth/forms/magic-link-form.tsx +191 -0
- package/src/components/auth/forms/recover-account-form.tsx +138 -0
- package/src/components/auth/forms/reset-password-form.tsx +215 -0
- package/src/components/auth/forms/sign-in-form.tsx +289 -0
- package/src/components/auth/forms/sign-up-form.tsx +788 -0
- package/src/components/auth/forms/two-factor-form.tsx +372 -0
- package/src/components/auth/magic-link-button.tsx +54 -0
- package/src/components/auth/one-tap.tsx +48 -0
- package/src/components/auth/otp-input-group.tsx +65 -0
- package/src/components/auth/passkey-button.tsx +85 -0
- package/src/components/auth/provider-button.tsx +141 -0
- package/src/components/auth/sign-out.tsx +25 -0
- package/src/components/auth-loading.tsx +21 -0
- package/src/components/captcha/captcha.tsx +79 -0
- package/src/components/captcha/recaptcha-badge.tsx +61 -0
- package/src/components/captcha/recaptcha-v2.tsx +58 -0
- package/src/components/captcha/recaptcha-v3.tsx +73 -0
- package/src/components/email/email-template.tsx +216 -0
- package/src/components/form-error.tsx +27 -0
- package/src/components/organization/accept-invitation-card.tsx +362 -0
- package/src/components/organization/create-organization-dialog.tsx +395 -0
- package/src/components/organization/delete-organization-card.tsx +101 -0
- package/src/components/organization/delete-organization-dialog.tsx +209 -0
- package/src/components/organization/invitation-cell.tsx +156 -0
- package/src/components/organization/invite-member-dialog.tsx +258 -0
- package/src/components/organization/leave-organization-dialog.tsx +150 -0
- package/src/components/organization/member-cell.tsx +187 -0
- package/src/components/organization/organization-cell-view.tsx +122 -0
- package/src/components/organization/organization-cell.tsx +154 -0
- package/src/components/organization/organization-invitations-card.tsx +94 -0
- package/src/components/organization/organization-logo-card.tsx +308 -0
- package/src/components/organization/organization-logo.tsx +120 -0
- package/src/components/organization/organization-members-card.tsx +155 -0
- package/src/components/organization/organization-name-card.tsx +204 -0
- package/src/components/organization/organization-settings-cards.tsx +67 -0
- package/src/components/organization/organization-slug-card.tsx +223 -0
- package/src/components/organization/organization-switcher.tsx +512 -0
- package/src/components/organization/organization-view.tsx +228 -0
- package/src/components/organization/organizations-card.tsx +72 -0
- package/src/components/organization/personal-account-view.tsx +115 -0
- package/src/components/organization/remove-member-dialog.tsx +144 -0
- package/src/components/organization/update-member-role-dialog.tsx +213 -0
- package/src/components/organization/user-invitations-card.tsx +238 -0
- package/src/components/password-input.tsx +56 -0
- package/src/components/provider-icons.tsx +385 -0
- package/src/components/redirect-to-sign-in.tsx +16 -0
- package/src/components/redirect-to-sign-up.tsx +16 -0
- package/src/components/settings/account/account-cell.tsx +158 -0
- package/src/components/settings/account/accounts-card.tsx +75 -0
- package/src/components/settings/account/delete-account-card.tsx +65 -0
- package/src/components/settings/account/delete-account-dialog.tsx +231 -0
- package/src/components/settings/account/update-avatar-card.tsx +198 -0
- package/src/components/settings/account/update-field-card.tsx +282 -0
- package/src/components/settings/account/update-name-card.tsx +39 -0
- package/src/components/settings/account/update-username-card.tsx +42 -0
- package/src/components/settings/account-settings-cards.tsx +123 -0
- package/src/components/settings/api-key/api-key-cell.tsx +108 -0
- package/src/components/settings/api-key/api-key-delete-dialog.tsx +162 -0
- package/src/components/settings/api-key/api-key-display-dialog.tsx +110 -0
- package/src/components/settings/api-key/api-keys-card.tsx +98 -0
- package/src/components/settings/api-key/create-api-key-dialog.tsx +376 -0
- package/src/components/settings/passkey/passkey-cell.tsx +113 -0
- package/src/components/settings/passkey/passkeys-card.tsx +111 -0
- package/src/components/settings/providers/provider-cell.tsx +152 -0
- package/src/components/settings/providers/providers-card.tsx +108 -0
- package/src/components/settings/security/change-email-card.tsx +200 -0
- package/src/components/settings/security/change-password-card.tsx +326 -0
- package/src/components/settings/security/session-cell.tsx +120 -0
- package/src/components/settings/security/sessions-card.tsx +58 -0
- package/src/components/settings/security-settings-cards.tsx +111 -0
- package/src/components/settings/shared/session-freshness-dialog.tsx +97 -0
- package/src/components/settings/shared/settings-action-button.tsx +51 -0
- package/src/components/settings/shared/settings-card-footer.tsx +94 -0
- package/src/components/settings/shared/settings-card-header.tsx +67 -0
- package/src/components/settings/shared/settings-card.tsx +106 -0
- package/src/components/settings/skeletons/input-field-skeleton.tsx +18 -0
- package/src/components/settings/skeletons/settings-cell-skeleton.tsx +37 -0
- package/src/components/settings/two-factor/backup-codes-dialog.tsx +113 -0
- package/src/components/settings/two-factor/two-factor-card.tsx +63 -0
- package/src/components/settings/two-factor/two-factor-password-dialog.tsx +226 -0
- package/src/components/signed-in.tsx +20 -0
- package/src/components/signed-out.tsx +20 -0
- package/src/components/ui/alert.tsx +66 -0
- package/src/components/ui/avatar.tsx +53 -0
- package/src/components/ui/button.tsx +59 -0
- package/src/components/ui/card.tsx +92 -0
- package/src/components/ui/checkbox.tsx +32 -0
- package/src/components/ui/dialog.tsx +143 -0
- package/src/components/ui/drawer.tsx +135 -0
- package/src/components/ui/dropdown-menu.tsx +257 -0
- package/src/components/ui/form.tsx +167 -0
- package/src/components/ui/input-otp.tsx +77 -0
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/label.tsx +24 -0
- package/src/components/ui/select.tsx +185 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/tabs.tsx +66 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/user-avatar.tsx +147 -0
- package/src/components/user-button.tsx +409 -0
- package/src/components/user-view.tsx +138 -0
- package/src/hooks/use-auth-data.ts +184 -0
- package/src/hooks/use-authenticate.ts +62 -0
- package/src/hooks/use-captcha.tsx +138 -0
- package/src/hooks/use-current-organization.ts +59 -0
- package/src/hooks/use-hydrated.ts +13 -0
- package/src/hooks/use-lang.ts +32 -0
- package/src/hooks/use-success-transition.ts +51 -0
- package/src/hooks/use-theme.ts +39 -0
- package/src/index.ts +65 -0
- package/src/instantdb.ts +1 -0
- package/src/lib/auth-data-cache.ts +90 -0
- package/src/lib/auth-ui-provider.tsx +658 -0
- package/src/lib/gravatar-utils.ts +58 -0
- package/src/lib/image-utils.ts +55 -0
- package/src/lib/instantdb/model-names.ts +24 -0
- package/src/lib/instantdb/use-instant-options.ts +98 -0
- package/src/lib/instantdb/use-list-accounts.ts +38 -0
- package/src/lib/instantdb/use-list-sessions.ts +53 -0
- package/src/lib/instantdb/use-session.ts +55 -0
- package/src/lib/organization-refetcher.tsx +56 -0
- package/src/lib/social-providers.ts +144 -0
- package/src/lib/tanstack/auth-ui-provider-tanstack.tsx +49 -0
- package/src/lib/tanstack/use-tanstack-options.ts +112 -0
- package/src/lib/triplit/model-names.ts +24 -0
- package/src/lib/triplit/use-conditional-query.ts +82 -0
- package/src/lib/triplit/use-list-accounts.ts +31 -0
- package/src/lib/triplit/use-list-sessions.ts +33 -0
- package/src/lib/triplit/use-session.ts +42 -0
- package/src/lib/triplit/use-triplit-hooks.ts +68 -0
- package/src/lib/triplit/use-triplit-token.ts +44 -0
- package/src/lib/utils.ts +105 -0
- package/src/lib/view-paths.ts +55 -0
- package/src/localization/admin-error-codes.ts +20 -0
- package/src/localization/anonymous-error-codes.ts +6 -0
- package/src/localization/api-key-error-codes.ts +32 -0
- package/src/localization/auth-localization.ts +740 -0
- package/src/localization/base-error-codes.ts +27 -0
- package/src/localization/captcha-error-codes.ts +17 -0
- package/src/localization/email-otp-error-codes.ts +7 -0
- package/src/localization/generic-oauth-error-codes.ts +3 -0
- package/src/localization/haveibeenpwned-error-codes.ts +4 -0
- package/src/localization/multi-session-error-codes.ts +3 -0
- package/src/localization/organization-error-codes.ts +57 -0
- package/src/localization/passkey-error-codes.ts +10 -0
- package/src/localization/phone-number-error-codes.ts +10 -0
- package/src/localization/stripe-localization.ts +12 -0
- package/src/localization/two-factor-error-codes.ts +12 -0
- package/src/localization/username-error-codes.ts +9 -0
- package/src/server.ts +4 -0
- package/src/style.css +1 -0
- package/src/tanstack.ts +1 -0
- package/src/triplit.ts +1 -0
- package/src/types/account-options.ts +35 -0
- package/src/types/additional-fields.ts +21 -0
- package/src/types/any-auth-client.ts +6 -0
- package/src/types/api-key.ts +9 -0
- package/src/types/auth-client.ts +37 -0
- package/src/types/auth-hooks.ts +61 -0
- package/src/types/auth-mutators.ts +17 -0
- package/src/types/avatar-options.ts +29 -0
- package/src/types/captcha-options.ts +32 -0
- package/src/types/captcha-provider.ts +6 -0
- package/src/types/credentials-options.ts +32 -0
- package/src/types/delete-user-options.ts +7 -0
- package/src/types/fetch-error.ts +6 -0
- package/src/types/generic-oauth-options.ts +16 -0
- package/src/types/gravatar-options.ts +21 -0
- package/src/types/image.ts +7 -0
- package/src/types/invitation.ts +10 -0
- package/src/types/link.ts +7 -0
- package/src/types/organization-options.ts +106 -0
- package/src/types/password-validation.ts +16 -0
- package/src/types/profile.ts +15 -0
- package/src/types/refetch.ts +1 -0
- package/src/types/render-toast.ts +9 -0
- package/src/types/sign-up-options.ts +7 -0
- package/src/types/social-options.ts +16 -0
package/package.json
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "better-auth-ui",
|
|
3
|
+
"homepage": "https://better-auth-ui.com",
|
|
4
|
+
"version": "3.2.5",
|
|
5
|
+
"description": "Plug & play shadcn/ui components for better-auth",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./css": "./dist/style.css",
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"./server": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/server.d.ts",
|
|
24
|
+
"default": "./dist/server.js"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/server.d.cts",
|
|
28
|
+
"default": "./dist/server.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"./tanstack": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/tanstack.d.ts",
|
|
34
|
+
"default": "./dist/tanstack.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/tanstack.d.cts",
|
|
38
|
+
"default": "./dist/tanstack.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./instantdb": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/instantdb.d.ts",
|
|
44
|
+
"default": "./dist/instantdb.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/instantdb.d.cts",
|
|
48
|
+
"default": "./dist/instantdb.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./triplit": {
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/triplit.d.ts",
|
|
54
|
+
"default": "./dist/triplit.js"
|
|
55
|
+
},
|
|
56
|
+
"require": {
|
|
57
|
+
"types": "./dist/triplit.d.cts",
|
|
58
|
+
"default": "./dist/triplit.cjs"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"files": [
|
|
63
|
+
"src",
|
|
64
|
+
"dist"
|
|
65
|
+
],
|
|
66
|
+
"keywords": [
|
|
67
|
+
"typescript",
|
|
68
|
+
"react",
|
|
69
|
+
"better-auth",
|
|
70
|
+
"shadcn",
|
|
71
|
+
"nextjs"
|
|
72
|
+
],
|
|
73
|
+
"author": "daveycodez",
|
|
74
|
+
"license": "MIT",
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@biomejs/biome": "2.2.4",
|
|
77
|
+
"@radix-ui/react-checkbox": "^1.3.3",
|
|
78
|
+
"@radix-ui/react-context": "^1.1.2",
|
|
79
|
+
"@radix-ui/react-dialog": "^1.1.15",
|
|
80
|
+
"@radix-ui/react-label": "^2.1.7",
|
|
81
|
+
"@radix-ui/react-primitive": "^2.1.3",
|
|
82
|
+
"@radix-ui/react-separator": "^1.1.7",
|
|
83
|
+
"@radix-ui/react-slot": "^1.2.3",
|
|
84
|
+
"@radix-ui/react-tabs": "^1.1.13",
|
|
85
|
+
"@radix-ui/react-use-callback-ref": "^1.1.1",
|
|
86
|
+
"@radix-ui/react-use-layout-effect": "^1.1.1",
|
|
87
|
+
"@tanstack/react-query": "^5.90.2",
|
|
88
|
+
"@types/node": "^24.5.2",
|
|
89
|
+
"@types/react": "^19.1.13",
|
|
90
|
+
"@types/react-dom": "^19.1.9",
|
|
91
|
+
"@types/react-google-recaptcha": "^2.1.9",
|
|
92
|
+
"better-auth": "^1.3.14",
|
|
93
|
+
"class-variance-authority": "^0.7.1",
|
|
94
|
+
"clsx": "^2.1.1",
|
|
95
|
+
"esbuild-plugin-preserve-directives": "^0.0.11",
|
|
96
|
+
"lucide-react": "^0.544.0",
|
|
97
|
+
"shx": "^0.4.0",
|
|
98
|
+
"tailwind-merge": "^3.3.1",
|
|
99
|
+
"tailwindcss-animate": "^1.0.7",
|
|
100
|
+
"tsc-watch": "^7.1.1",
|
|
101
|
+
"tsup": "^8.5.0",
|
|
102
|
+
"tsx": "^4.20.5",
|
|
103
|
+
"turbo": "^2.5.7",
|
|
104
|
+
"typescript": "^5.9.2",
|
|
105
|
+
"zod": "^4.1.11"
|
|
106
|
+
},
|
|
107
|
+
"peerDependencies": {
|
|
108
|
+
"@daveyplate/better-auth-tanstack": "^1.3.6",
|
|
109
|
+
"@hookform/resolvers": ">=5.2.0",
|
|
110
|
+
"@instantdb/react": ">=0.18.0",
|
|
111
|
+
"@marsidev/react-turnstile": ">=1.1.0",
|
|
112
|
+
"@radix-ui/react-avatar": ">=1.1.0",
|
|
113
|
+
"@radix-ui/react-checkbox": ">=1.1.0",
|
|
114
|
+
"@radix-ui/react-context": ">=1.1.0",
|
|
115
|
+
"@radix-ui/react-dialog": ">=1.1.0",
|
|
116
|
+
"@radix-ui/react-dropdown-menu": ">=2.1.0",
|
|
117
|
+
"@radix-ui/react-label": ">=2.1.0",
|
|
118
|
+
"@radix-ui/react-primitive": ">=2.0.0",
|
|
119
|
+
"@radix-ui/react-select": ">=2.2.0",
|
|
120
|
+
"@radix-ui/react-separator": ">=1.1.0",
|
|
121
|
+
"@radix-ui/react-slot": ">=1.1.0",
|
|
122
|
+
"@radix-ui/react-tabs": ">=1.1.0",
|
|
123
|
+
"@radix-ui/react-use-callback-ref": ">=1.1.0",
|
|
124
|
+
"@radix-ui/react-use-layout-effect": ">=1.1.0",
|
|
125
|
+
"@tanstack/react-query": ">=5.66.0",
|
|
126
|
+
"@triplit/client": ">=1.0.0",
|
|
127
|
+
"@triplit/react": ">=1.0.0",
|
|
128
|
+
"better-auth": "^1.3.13",
|
|
129
|
+
"class-variance-authority": ">=0.7.0",
|
|
130
|
+
"clsx": ">=2.1.0",
|
|
131
|
+
"input-otp": ">=1.4.0",
|
|
132
|
+
"lucide-react": ">=0.469.0",
|
|
133
|
+
"react": ">=18.0.0",
|
|
134
|
+
"react-dom": ">=18.0.0",
|
|
135
|
+
"react-hook-form": ">=7.55.0",
|
|
136
|
+
"sonner": ">=1.7.0",
|
|
137
|
+
"tailwind-merge": ">=2.6.0",
|
|
138
|
+
"tailwindcss": ">=3.0.0",
|
|
139
|
+
"zod": ">=3.0.0"
|
|
140
|
+
},
|
|
141
|
+
"dependencies": {
|
|
142
|
+
"@better-fetch/fetch": "^1.1.18",
|
|
143
|
+
"@hcaptcha/react-hcaptcha": "^1.12.1",
|
|
144
|
+
"@noble/hashes": "^2.0.1",
|
|
145
|
+
"@react-email/components": "^0.5.4",
|
|
146
|
+
"@wojtekmaj/react-recaptcha-v3": "^0.1.4",
|
|
147
|
+
"react-google-recaptcha": "^3.1.0",
|
|
148
|
+
"react-qr-code": "^2.0.18",
|
|
149
|
+
"ua-parser-js": "^2.0.5",
|
|
150
|
+
"vaul": "^1.1.2"
|
|
151
|
+
},
|
|
152
|
+
"scripts": {
|
|
153
|
+
"build": "tsup --clean --dts && shx cp src/style.css dist/style.css",
|
|
154
|
+
"dev": "tsc-watch"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { MenuIcon } from "lucide-react"
|
|
4
|
+
import { useContext, useMemo } from "react"
|
|
5
|
+
import { useAuthenticate } from "../../hooks/use-authenticate"
|
|
6
|
+
import { AuthUIContext } from "../../lib/auth-ui-provider"
|
|
7
|
+
import { cn, getViewByPath } from "../../lib/utils"
|
|
8
|
+
import type { AuthLocalization } from "../../localization/auth-localization"
|
|
9
|
+
import type { AccountViewPath } from "../../server"
|
|
10
|
+
import { OrganizationsCard } from "../organization/organizations-card"
|
|
11
|
+
import { UserInvitationsCard } from "../organization/user-invitations-card"
|
|
12
|
+
import { AccountSettingsCards } from "../settings/account-settings-cards"
|
|
13
|
+
import { ApiKeysCard } from "../settings/api-key/api-keys-card"
|
|
14
|
+
import { SecuritySettingsCards } from "../settings/security-settings-cards"
|
|
15
|
+
import type { SettingsCardClassNames } from "../settings/shared/settings-card"
|
|
16
|
+
import { Button } from "../ui/button"
|
|
17
|
+
import {
|
|
18
|
+
Drawer,
|
|
19
|
+
DrawerContent,
|
|
20
|
+
DrawerHeader,
|
|
21
|
+
DrawerTitle,
|
|
22
|
+
DrawerTrigger
|
|
23
|
+
} from "../ui/drawer"
|
|
24
|
+
import { Label } from "../ui/label"
|
|
25
|
+
|
|
26
|
+
export interface AccountViewProps {
|
|
27
|
+
className?: string
|
|
28
|
+
classNames?: {
|
|
29
|
+
base?: string
|
|
30
|
+
cards?: string
|
|
31
|
+
drawer?: { menuItem?: string }
|
|
32
|
+
sidebar?: { base?: string; button?: string; buttonActive?: string }
|
|
33
|
+
card?: SettingsCardClassNames
|
|
34
|
+
}
|
|
35
|
+
localization?: AuthLocalization
|
|
36
|
+
path?: string
|
|
37
|
+
pathname?: string
|
|
38
|
+
view?: AccountViewPath
|
|
39
|
+
hideNav?: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function AccountView({
|
|
43
|
+
className,
|
|
44
|
+
classNames,
|
|
45
|
+
localization: localizationProp,
|
|
46
|
+
path: pathProp,
|
|
47
|
+
pathname,
|
|
48
|
+
view: viewProp,
|
|
49
|
+
hideNav
|
|
50
|
+
}: AccountViewProps) {
|
|
51
|
+
const {
|
|
52
|
+
apiKey,
|
|
53
|
+
localization: contextLocalization,
|
|
54
|
+
organization,
|
|
55
|
+
account: accountOptions,
|
|
56
|
+
Link
|
|
57
|
+
} = useContext(AuthUIContext)
|
|
58
|
+
|
|
59
|
+
if (!accountOptions) {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
useAuthenticate()
|
|
64
|
+
|
|
65
|
+
const localization = useMemo(
|
|
66
|
+
() => ({ ...contextLocalization, ...localizationProp }),
|
|
67
|
+
[contextLocalization, localizationProp]
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
const path = pathProp ?? pathname?.split("/").pop()
|
|
71
|
+
|
|
72
|
+
const view =
|
|
73
|
+
viewProp || getViewByPath(accountOptions.viewPaths, path!) || "SETTINGS"
|
|
74
|
+
|
|
75
|
+
const navItems: {
|
|
76
|
+
view: AccountViewPath
|
|
77
|
+
label: string
|
|
78
|
+
}[] = [
|
|
79
|
+
{ view: "SETTINGS", label: localization.ACCOUNT },
|
|
80
|
+
{ view: "SECURITY", label: localization.SECURITY }
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
if (apiKey) {
|
|
84
|
+
navItems.push({
|
|
85
|
+
view: "API_KEYS",
|
|
86
|
+
label: localization.API_KEYS
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (organization) {
|
|
91
|
+
navItems.push({
|
|
92
|
+
view: "ORGANIZATIONS",
|
|
93
|
+
label: localization.ORGANIZATIONS
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<div
|
|
99
|
+
className={cn(
|
|
100
|
+
"flex w-full grow flex-col gap-4 md:flex-row md:gap-12",
|
|
101
|
+
className,
|
|
102
|
+
classNames?.base
|
|
103
|
+
)}
|
|
104
|
+
>
|
|
105
|
+
{!hideNav && (
|
|
106
|
+
<div className="flex justify-between gap-2 md:hidden">
|
|
107
|
+
<Label className="font-semibold text-base">
|
|
108
|
+
{navItems.find((i) => i.view === view)?.label}
|
|
109
|
+
</Label>
|
|
110
|
+
|
|
111
|
+
<Drawer>
|
|
112
|
+
<DrawerTrigger asChild>
|
|
113
|
+
<Button variant="outline">
|
|
114
|
+
<MenuIcon />
|
|
115
|
+
</Button>
|
|
116
|
+
</DrawerTrigger>
|
|
117
|
+
<DrawerContent>
|
|
118
|
+
<DrawerHeader>
|
|
119
|
+
<DrawerTitle className="hidden">
|
|
120
|
+
{localization.SETTINGS}
|
|
121
|
+
</DrawerTitle>
|
|
122
|
+
</DrawerHeader>
|
|
123
|
+
<div className="flex flex-col px-4 pb-4">
|
|
124
|
+
{navItems.map((item) => (
|
|
125
|
+
<Link
|
|
126
|
+
key={item.view}
|
|
127
|
+
href={`${accountOptions?.basePath}/${accountOptions?.viewPaths[item.view]}`}
|
|
128
|
+
>
|
|
129
|
+
<Button
|
|
130
|
+
size="lg"
|
|
131
|
+
className={cn(
|
|
132
|
+
"w-full justify-start px-4 transition-none",
|
|
133
|
+
classNames?.drawer?.menuItem,
|
|
134
|
+
view === item.view
|
|
135
|
+
? "font-semibold"
|
|
136
|
+
: "text-foreground/70"
|
|
137
|
+
)}
|
|
138
|
+
variant="ghost"
|
|
139
|
+
>
|
|
140
|
+
{item.label}
|
|
141
|
+
</Button>
|
|
142
|
+
</Link>
|
|
143
|
+
))}
|
|
144
|
+
</div>
|
|
145
|
+
</DrawerContent>
|
|
146
|
+
</Drawer>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
{!hideNav && (
|
|
151
|
+
<div className="hidden md:block">
|
|
152
|
+
<div
|
|
153
|
+
className={cn(
|
|
154
|
+
"flex w-48 flex-col gap-1 lg:w-60",
|
|
155
|
+
classNames?.sidebar?.base
|
|
156
|
+
)}
|
|
157
|
+
>
|
|
158
|
+
{navItems.map((item) => (
|
|
159
|
+
<Link
|
|
160
|
+
key={item.view}
|
|
161
|
+
href={`${accountOptions?.basePath}/${accountOptions?.viewPaths[item.view]}`}
|
|
162
|
+
>
|
|
163
|
+
<Button
|
|
164
|
+
size="lg"
|
|
165
|
+
className={cn(
|
|
166
|
+
"w-full justify-start px-4 transition-none",
|
|
167
|
+
classNames?.sidebar?.button,
|
|
168
|
+
view === item.view
|
|
169
|
+
? "font-semibold"
|
|
170
|
+
: "text-foreground/70",
|
|
171
|
+
view === item.view &&
|
|
172
|
+
classNames?.sidebar?.buttonActive
|
|
173
|
+
)}
|
|
174
|
+
variant="ghost"
|
|
175
|
+
>
|
|
176
|
+
{item.label}
|
|
177
|
+
</Button>
|
|
178
|
+
</Link>
|
|
179
|
+
))}
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
)}
|
|
183
|
+
|
|
184
|
+
{view === "SETTINGS" && (
|
|
185
|
+
<AccountSettingsCards
|
|
186
|
+
classNames={classNames}
|
|
187
|
+
localization={localization}
|
|
188
|
+
/>
|
|
189
|
+
)}
|
|
190
|
+
|
|
191
|
+
{view === "SECURITY" && (
|
|
192
|
+
<SecuritySettingsCards
|
|
193
|
+
classNames={classNames}
|
|
194
|
+
localization={localization}
|
|
195
|
+
/>
|
|
196
|
+
)}
|
|
197
|
+
|
|
198
|
+
{view === "API_KEYS" && (
|
|
199
|
+
<ApiKeysCard
|
|
200
|
+
classNames={classNames?.card}
|
|
201
|
+
localization={localization}
|
|
202
|
+
/>
|
|
203
|
+
)}
|
|
204
|
+
|
|
205
|
+
{view === "ORGANIZATIONS" && organization && (
|
|
206
|
+
<div className="grid w-full gap-4 md:gap-6">
|
|
207
|
+
<OrganizationsCard
|
|
208
|
+
classNames={classNames?.card}
|
|
209
|
+
localization={localization}
|
|
210
|
+
/>
|
|
211
|
+
|
|
212
|
+
<UserInvitationsCard
|
|
213
|
+
classNames={classNames?.card}
|
|
214
|
+
localization={localization}
|
|
215
|
+
/>
|
|
216
|
+
</div>
|
|
217
|
+
)}
|
|
218
|
+
</div>
|
|
219
|
+
)
|
|
220
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { Loader2 } from "lucide-react"
|
|
4
|
+
import { useContext, useEffect, useRef } from "react"
|
|
5
|
+
|
|
6
|
+
import { useOnSuccessTransition } from "../../hooks/use-success-transition"
|
|
7
|
+
import { AuthUIContext } from "../../lib/auth-ui-provider"
|
|
8
|
+
|
|
9
|
+
export function AuthCallback({ redirectTo }: { redirectTo?: string }) {
|
|
10
|
+
const {
|
|
11
|
+
hooks: { useIsRestoring },
|
|
12
|
+
persistClient
|
|
13
|
+
} = useContext(AuthUIContext)
|
|
14
|
+
|
|
15
|
+
const isRestoring = useIsRestoring?.()
|
|
16
|
+
const isRedirecting = useRef(false)
|
|
17
|
+
|
|
18
|
+
const { onSuccess } = useOnSuccessTransition({ redirectTo })
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (isRedirecting.current) return
|
|
22
|
+
|
|
23
|
+
if (!persistClient) {
|
|
24
|
+
isRedirecting.current = true
|
|
25
|
+
onSuccess()
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (isRestoring) return
|
|
30
|
+
|
|
31
|
+
isRedirecting.current = true
|
|
32
|
+
onSuccess()
|
|
33
|
+
}, [isRestoring, persistClient, onSuccess])
|
|
34
|
+
|
|
35
|
+
return <Loader2 className="animate-spin" />
|
|
36
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useContext, useEffect } from "react"
|
|
4
|
+
|
|
5
|
+
import { AuthUIContext } from "../../lib/auth-ui-provider"
|
|
6
|
+
import { getViewByPath } from "../../lib/utils"
|
|
7
|
+
import type { AuthViewPath } from "../../lib/view-paths"
|
|
8
|
+
import type { AuthLocalization } from "../../localization/auth-localization"
|
|
9
|
+
import { AuthCallback } from "./auth-callback"
|
|
10
|
+
import { EmailOTPForm } from "./forms/email-otp-form"
|
|
11
|
+
import { ForgotPasswordForm } from "./forms/forgot-password-form"
|
|
12
|
+
import { MagicLinkForm } from "./forms/magic-link-form"
|
|
13
|
+
import { RecoverAccountForm } from "./forms/recover-account-form"
|
|
14
|
+
import { ResetPasswordForm } from "./forms/reset-password-form"
|
|
15
|
+
import { SignInForm } from "./forms/sign-in-form"
|
|
16
|
+
import { SignUpForm } from "./forms/sign-up-form"
|
|
17
|
+
import { TwoFactorForm } from "./forms/two-factor-form"
|
|
18
|
+
import { SignOut } from "./sign-out"
|
|
19
|
+
|
|
20
|
+
export type AuthFormClassNames = {
|
|
21
|
+
base?: string
|
|
22
|
+
button?: string
|
|
23
|
+
checkbox?: string
|
|
24
|
+
description?: string
|
|
25
|
+
error?: string
|
|
26
|
+
forgotPasswordLink?: string
|
|
27
|
+
icon?: string
|
|
28
|
+
input?: string
|
|
29
|
+
label?: string
|
|
30
|
+
otpInput?: string
|
|
31
|
+
otpInputContainer?: string
|
|
32
|
+
outlineButton?: string
|
|
33
|
+
primaryButton?: string
|
|
34
|
+
providerButton?: string
|
|
35
|
+
qrCode?: string
|
|
36
|
+
secondaryButton?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AuthFormProps {
|
|
40
|
+
className?: string
|
|
41
|
+
classNames?: AuthFormClassNames
|
|
42
|
+
callbackURL?: string
|
|
43
|
+
isSubmitting?: boolean
|
|
44
|
+
localization?: Partial<AuthLocalization>
|
|
45
|
+
pathname?: string
|
|
46
|
+
redirectTo?: string
|
|
47
|
+
view?: AuthViewPath
|
|
48
|
+
otpSeparators?: 0 | 1 | 2
|
|
49
|
+
setIsSubmitting?: (isSubmitting: boolean) => void
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function AuthForm({
|
|
53
|
+
className,
|
|
54
|
+
classNames,
|
|
55
|
+
callbackURL,
|
|
56
|
+
isSubmitting,
|
|
57
|
+
localization,
|
|
58
|
+
pathname,
|
|
59
|
+
redirectTo,
|
|
60
|
+
view,
|
|
61
|
+
otpSeparators = 0,
|
|
62
|
+
setIsSubmitting
|
|
63
|
+
}: AuthFormProps) {
|
|
64
|
+
const {
|
|
65
|
+
basePath,
|
|
66
|
+
credentials,
|
|
67
|
+
localization: contextLocalization,
|
|
68
|
+
magicLink,
|
|
69
|
+
emailOTP,
|
|
70
|
+
signUp,
|
|
71
|
+
twoFactor: twoFactorEnabled,
|
|
72
|
+
viewPaths,
|
|
73
|
+
replace
|
|
74
|
+
} = useContext(AuthUIContext)
|
|
75
|
+
|
|
76
|
+
const signUpEnabled = !!signUp
|
|
77
|
+
|
|
78
|
+
localization = { ...contextLocalization, ...localization }
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (pathname && !getViewByPath(viewPaths, pathname)) {
|
|
82
|
+
console.error(`Invalid auth view: ${pathname}`)
|
|
83
|
+
replace(`${basePath}/${viewPaths.SIGN_IN}${window.location.search}`)
|
|
84
|
+
}
|
|
85
|
+
}, [pathname, viewPaths, basePath, replace])
|
|
86
|
+
|
|
87
|
+
view =
|
|
88
|
+
view ||
|
|
89
|
+
(getViewByPath(viewPaths, pathname) as AuthViewPath) ||
|
|
90
|
+
"SIGN_IN"
|
|
91
|
+
|
|
92
|
+
// Redirect to appropriate view based on enabled features
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
let isInvalidView = false
|
|
95
|
+
|
|
96
|
+
if (
|
|
97
|
+
view === "MAGIC_LINK" &&
|
|
98
|
+
(!magicLink || (!credentials && !emailOTP))
|
|
99
|
+
) {
|
|
100
|
+
isInvalidView = true
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (
|
|
104
|
+
view === "EMAIL_OTP" &&
|
|
105
|
+
(!emailOTP || (!credentials && !magicLink))
|
|
106
|
+
) {
|
|
107
|
+
isInvalidView = true
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (view === "SIGN_UP" && !signUpEnabled) {
|
|
111
|
+
isInvalidView = true
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (
|
|
115
|
+
!credentials &&
|
|
116
|
+
[
|
|
117
|
+
"SIGN_UP",
|
|
118
|
+
"FORGOT_PASSWORD",
|
|
119
|
+
"RESET_PASSWORD",
|
|
120
|
+
"TWO_FACTOR",
|
|
121
|
+
"RECOVER_ACCOUNT"
|
|
122
|
+
].includes(view)
|
|
123
|
+
) {
|
|
124
|
+
isInvalidView = true
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (
|
|
128
|
+
["TWO_FACTOR", "RECOVER_ACCOUNT"].includes(view) &&
|
|
129
|
+
!twoFactorEnabled
|
|
130
|
+
) {
|
|
131
|
+
isInvalidView = true
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (isInvalidView) {
|
|
135
|
+
replace(`${basePath}/${viewPaths.SIGN_IN}${window.location.search}`)
|
|
136
|
+
}
|
|
137
|
+
}, [
|
|
138
|
+
basePath,
|
|
139
|
+
view,
|
|
140
|
+
viewPaths,
|
|
141
|
+
credentials,
|
|
142
|
+
replace,
|
|
143
|
+
emailOTP,
|
|
144
|
+
signUpEnabled,
|
|
145
|
+
magicLink,
|
|
146
|
+
twoFactorEnabled
|
|
147
|
+
])
|
|
148
|
+
|
|
149
|
+
if (view === "SIGN_OUT") return <SignOut />
|
|
150
|
+
if (view === "CALLBACK") return <AuthCallback redirectTo={redirectTo} />
|
|
151
|
+
|
|
152
|
+
if (view === "SIGN_IN") {
|
|
153
|
+
return credentials ? (
|
|
154
|
+
<SignInForm
|
|
155
|
+
className={className}
|
|
156
|
+
classNames={classNames}
|
|
157
|
+
localization={localization}
|
|
158
|
+
redirectTo={redirectTo}
|
|
159
|
+
isSubmitting={isSubmitting}
|
|
160
|
+
setIsSubmitting={setIsSubmitting}
|
|
161
|
+
/>
|
|
162
|
+
) : magicLink ? (
|
|
163
|
+
<MagicLinkForm
|
|
164
|
+
className={className}
|
|
165
|
+
classNames={classNames}
|
|
166
|
+
callbackURL={callbackURL}
|
|
167
|
+
localization={localization}
|
|
168
|
+
redirectTo={redirectTo}
|
|
169
|
+
isSubmitting={isSubmitting}
|
|
170
|
+
setIsSubmitting={setIsSubmitting}
|
|
171
|
+
/>
|
|
172
|
+
) : emailOTP ? (
|
|
173
|
+
<EmailOTPForm
|
|
174
|
+
className={className}
|
|
175
|
+
classNames={classNames}
|
|
176
|
+
callbackURL={callbackURL}
|
|
177
|
+
localization={localization}
|
|
178
|
+
redirectTo={redirectTo}
|
|
179
|
+
isSubmitting={isSubmitting}
|
|
180
|
+
setIsSubmitting={setIsSubmitting}
|
|
181
|
+
/>
|
|
182
|
+
) : null
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (view === "TWO_FACTOR") {
|
|
186
|
+
return (
|
|
187
|
+
<TwoFactorForm
|
|
188
|
+
className={className}
|
|
189
|
+
classNames={classNames}
|
|
190
|
+
localization={localization}
|
|
191
|
+
otpSeparators={otpSeparators}
|
|
192
|
+
redirectTo={redirectTo}
|
|
193
|
+
isSubmitting={isSubmitting}
|
|
194
|
+
setIsSubmitting={setIsSubmitting}
|
|
195
|
+
/>
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (view === "RECOVER_ACCOUNT") {
|
|
200
|
+
return (
|
|
201
|
+
<RecoverAccountForm
|
|
202
|
+
className={className}
|
|
203
|
+
classNames={classNames}
|
|
204
|
+
localization={localization}
|
|
205
|
+
redirectTo={redirectTo}
|
|
206
|
+
isSubmitting={isSubmitting}
|
|
207
|
+
setIsSubmitting={setIsSubmitting}
|
|
208
|
+
/>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (view === "MAGIC_LINK") {
|
|
213
|
+
return (
|
|
214
|
+
<MagicLinkForm
|
|
215
|
+
className={className}
|
|
216
|
+
classNames={classNames}
|
|
217
|
+
callbackURL={callbackURL}
|
|
218
|
+
localization={localization}
|
|
219
|
+
redirectTo={redirectTo}
|
|
220
|
+
isSubmitting={isSubmitting}
|
|
221
|
+
setIsSubmitting={setIsSubmitting}
|
|
222
|
+
/>
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (view === "EMAIL_OTP") {
|
|
227
|
+
return (
|
|
228
|
+
<EmailOTPForm
|
|
229
|
+
className={className}
|
|
230
|
+
classNames={classNames}
|
|
231
|
+
callbackURL={callbackURL}
|
|
232
|
+
localization={localization}
|
|
233
|
+
redirectTo={redirectTo}
|
|
234
|
+
isSubmitting={isSubmitting}
|
|
235
|
+
setIsSubmitting={setIsSubmitting}
|
|
236
|
+
/>
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (view === "FORGOT_PASSWORD") {
|
|
241
|
+
return (
|
|
242
|
+
<ForgotPasswordForm
|
|
243
|
+
className={className}
|
|
244
|
+
classNames={classNames}
|
|
245
|
+
localization={localization}
|
|
246
|
+
isSubmitting={isSubmitting}
|
|
247
|
+
setIsSubmitting={setIsSubmitting}
|
|
248
|
+
/>
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (view === "RESET_PASSWORD") {
|
|
253
|
+
return (
|
|
254
|
+
<ResetPasswordForm
|
|
255
|
+
className={className}
|
|
256
|
+
classNames={classNames}
|
|
257
|
+
localization={localization}
|
|
258
|
+
/>
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (view === "SIGN_UP") {
|
|
263
|
+
return (
|
|
264
|
+
signUpEnabled && (
|
|
265
|
+
<SignUpForm
|
|
266
|
+
className={className}
|
|
267
|
+
classNames={classNames}
|
|
268
|
+
callbackURL={callbackURL}
|
|
269
|
+
localization={localization}
|
|
270
|
+
redirectTo={redirectTo}
|
|
271
|
+
isSubmitting={isSubmitting}
|
|
272
|
+
setIsSubmitting={setIsSubmitting}
|
|
273
|
+
/>
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
}
|