@erikey/react 0.4.26 → 0.4.28

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.
Files changed (145) hide show
  1. package/dist/index.mjs +1 -1
  2. package/dist/index.mjs.map +1 -1
  3. package/package.json +2 -1
  4. package/src/__tests__/auth-client.test.ts +105 -0
  5. package/src/__tests__/security/localStorage-encryption.test.ts +171 -0
  6. package/src/auth-client.ts +158 -0
  7. package/src/dashboard-client.ts +60 -0
  8. package/src/index.ts +88 -0
  9. package/src/kv-client.ts +316 -0
  10. package/src/lib/cross-origin-auth.ts +99 -0
  11. package/src/stubs/captcha.ts +24 -0
  12. package/src/stubs/hashes.ts +16 -0
  13. package/src/stubs/index.ts +17 -0
  14. package/src/stubs/passkey.ts +12 -0
  15. package/src/stubs/qr-code.ts +10 -0
  16. package/src/stubs/query.ts +16 -0
  17. package/src/stubs/realtime.ts +17 -0
  18. package/src/stubs/use-sync-external-store.ts +12 -0
  19. package/src/styles.css +141 -0
  20. package/src/types.ts +14 -0
  21. package/src/ui/components/auth/auth-callback.tsx +36 -0
  22. package/src/ui/components/auth/auth-form.tsx +310 -0
  23. package/src/ui/components/auth/auth-view.tsx +435 -0
  24. package/src/ui/components/auth/email-otp-button.tsx +53 -0
  25. package/src/ui/components/auth/forms/email-otp-form.tsx +312 -0
  26. package/src/ui/components/auth/forms/email-verification-form.tsx +271 -0
  27. package/src/ui/components/auth/forms/forgot-password-form.tsx +173 -0
  28. package/src/ui/components/auth/forms/magic-link-form.tsx +196 -0
  29. package/src/ui/components/auth/forms/recover-account-form.tsx +143 -0
  30. package/src/ui/components/auth/forms/reset-password-form.tsx +220 -0
  31. package/src/ui/components/auth/forms/sign-in-form.tsx +323 -0
  32. package/src/ui/components/auth/forms/sign-up-form.tsx +820 -0
  33. package/src/ui/components/auth/forms/two-factor-form.tsx +381 -0
  34. package/src/ui/components/auth/magic-link-button.tsx +54 -0
  35. package/src/ui/components/auth/one-tap.tsx +53 -0
  36. package/src/ui/components/auth/otp-input-group.tsx +65 -0
  37. package/src/ui/components/auth/passkey-button.tsx +91 -0
  38. package/src/ui/components/auth/provider-button.tsx +155 -0
  39. package/src/ui/components/auth/sign-out.tsx +25 -0
  40. package/src/ui/components/auth/wallet-button.tsx +192 -0
  41. package/src/ui/components/auth-loading.tsx +21 -0
  42. package/src/ui/components/captcha/captcha.tsx +91 -0
  43. package/src/ui/components/captcha/recaptcha-badge.tsx +61 -0
  44. package/src/ui/components/captcha/recaptcha-v2.tsx +58 -0
  45. package/src/ui/components/captcha/recaptcha-v3.tsx +73 -0
  46. package/src/ui/components/email/email-template.tsx +216 -0
  47. package/src/ui/components/form-error.tsx +27 -0
  48. package/src/ui/components/password-input.tsx +56 -0
  49. package/src/ui/components/provider-icons.tsx +404 -0
  50. package/src/ui/components/redirect-to-sign-in.tsx +16 -0
  51. package/src/ui/components/redirect-to-sign-up.tsx +16 -0
  52. package/src/ui/components/signed-in.tsx +20 -0
  53. package/src/ui/components/signed-out.tsx +20 -0
  54. package/src/ui/components/ui/alert.tsx +66 -0
  55. package/src/ui/components/ui/button.tsx +70 -0
  56. package/src/ui/components/ui/card.tsx +92 -0
  57. package/src/ui/components/ui/checkbox.tsx +66 -0
  58. package/src/ui/components/ui/field.tsx +248 -0
  59. package/src/ui/components/ui/form.tsx +165 -0
  60. package/src/ui/components/ui/input-otp.tsx +77 -0
  61. package/src/ui/components/ui/input.tsx +21 -0
  62. package/src/ui/components/ui/label.tsx +23 -0
  63. package/src/ui/components/ui/separator.tsx +34 -0
  64. package/src/ui/components/ui/skeleton.tsx +13 -0
  65. package/src/ui/components/ui/textarea.tsx +18 -0
  66. package/src/ui/components/user-avatar.tsx +151 -0
  67. package/src/ui/hooks/use-auth-data.ts +193 -0
  68. package/src/ui/hooks/use-authenticate.ts +64 -0
  69. package/src/ui/hooks/use-captcha.tsx +151 -0
  70. package/src/ui/hooks/use-hydrated.ts +13 -0
  71. package/src/ui/hooks/use-lang.ts +32 -0
  72. package/src/ui/hooks/use-success-transition.ts +41 -0
  73. package/src/ui/hooks/use-theme.ts +39 -0
  74. package/src/ui/index.ts +46 -0
  75. package/src/ui/instantdb.ts +1 -0
  76. package/src/ui/lib/auth-data-cache.ts +90 -0
  77. package/src/ui/lib/auth-ui-provider.tsx +769 -0
  78. package/src/ui/lib/gravatar-utils.ts +58 -0
  79. package/src/ui/lib/image-utils.ts +55 -0
  80. package/src/ui/lib/instantdb/model-names.ts +24 -0
  81. package/src/ui/lib/instantdb/use-instant-options.ts +98 -0
  82. package/src/ui/lib/instantdb/use-list-accounts.ts +38 -0
  83. package/src/ui/lib/instantdb/use-list-sessions.ts +53 -0
  84. package/src/ui/lib/instantdb/use-session.ts +55 -0
  85. package/src/ui/lib/social-providers.ts +150 -0
  86. package/src/ui/lib/tanstack/auth-ui-provider-tanstack.tsx +49 -0
  87. package/src/ui/lib/tanstack/use-tanstack-options.ts +112 -0
  88. package/src/ui/lib/triplit/model-names.ts +24 -0
  89. package/src/ui/lib/triplit/use-conditional-query.ts +82 -0
  90. package/src/ui/lib/triplit/use-list-accounts.ts +31 -0
  91. package/src/ui/lib/triplit/use-list-sessions.ts +33 -0
  92. package/src/ui/lib/triplit/use-session.ts +42 -0
  93. package/src/ui/lib/triplit/use-triplit-hooks.ts +68 -0
  94. package/src/ui/lib/triplit/use-triplit-token.ts +44 -0
  95. package/src/ui/lib/utils.ts +119 -0
  96. package/src/ui/lib/view-paths.ts +61 -0
  97. package/src/ui/lib/wallet.ts +129 -0
  98. package/src/ui/localization/admin-error-codes.ts +20 -0
  99. package/src/ui/localization/anonymous-error-codes.ts +6 -0
  100. package/src/ui/localization/api-key-error-codes.ts +32 -0
  101. package/src/ui/localization/auth-localization.ts +865 -0
  102. package/src/ui/localization/base-error-codes.ts +27 -0
  103. package/src/ui/localization/captcha-error-codes.ts +17 -0
  104. package/src/ui/localization/email-otp-error-codes.ts +7 -0
  105. package/src/ui/localization/generic-oauth-error-codes.ts +3 -0
  106. package/src/ui/localization/haveibeenpwned-error-codes.ts +4 -0
  107. package/src/ui/localization/multi-session-error-codes.ts +3 -0
  108. package/src/ui/localization/organization-error-codes.ts +57 -0
  109. package/src/ui/localization/passkey-error-codes.ts +10 -0
  110. package/src/ui/localization/phone-number-error-codes.ts +10 -0
  111. package/src/ui/localization/stripe-localization.ts +12 -0
  112. package/src/ui/localization/team-error-codes.ts +12 -0
  113. package/src/ui/localization/two-factor-error-codes.ts +12 -0
  114. package/src/ui/localization/username-error-codes.ts +9 -0
  115. package/src/ui/server.ts +4 -0
  116. package/src/ui/style.css +146 -0
  117. package/src/ui/tanstack.ts +1 -0
  118. package/src/ui/triplit.ts +1 -0
  119. package/src/ui/types/account-options.ts +35 -0
  120. package/src/ui/types/additional-fields.ts +21 -0
  121. package/src/ui/types/any-auth-client.ts +6 -0
  122. package/src/ui/types/api-key.ts +9 -0
  123. package/src/ui/types/auth-client.ts +41 -0
  124. package/src/ui/types/auth-hooks.ts +81 -0
  125. package/src/ui/types/auth-mutators.ts +21 -0
  126. package/src/ui/types/avatar-options.ts +29 -0
  127. package/src/ui/types/captcha-options.ts +32 -0
  128. package/src/ui/types/captcha-provider.ts +7 -0
  129. package/src/ui/types/credentials-options.ts +38 -0
  130. package/src/ui/types/delete-user-options.ts +7 -0
  131. package/src/ui/types/email-verification-options.ts +7 -0
  132. package/src/ui/types/fetch-error.ts +6 -0
  133. package/src/ui/types/generic-oauth-options.ts +16 -0
  134. package/src/ui/types/gravatar-options.ts +21 -0
  135. package/src/ui/types/image.ts +7 -0
  136. package/src/ui/types/invitation.ts +10 -0
  137. package/src/ui/types/link.ts +7 -0
  138. package/src/ui/types/organization-options.ts +106 -0
  139. package/src/ui/types/password-validation.ts +16 -0
  140. package/src/ui/types/profile.ts +15 -0
  141. package/src/ui/types/refetch.ts +1 -0
  142. package/src/ui/types/render-toast.ts +9 -0
  143. package/src/ui/types/sign-up-options.ts +7 -0
  144. package/src/ui/types/social-options.ts +16 -0
  145. package/src/ui/types/team-options.ts +47 -0
@@ -0,0 +1,41 @@
1
+ import { useCallback, useContext, useState } from "react"
2
+ import { AuthUIContext } from "../lib/auth-ui-provider"
3
+ import { getSearchParam } from "../lib/utils"
4
+
5
+ export function useOnSuccessTransition({
6
+ redirectTo: redirectToProp
7
+ }: {
8
+ redirectTo?: string
9
+ }) {
10
+ const { redirectTo: contextRedirectTo } = useContext(AuthUIContext)
11
+
12
+ const getRedirectTo = useCallback(
13
+ () =>
14
+ redirectToProp || getSearchParam("redirectTo") || contextRedirectTo,
15
+ [redirectToProp, contextRedirectTo]
16
+ )
17
+
18
+ const [isPending, setIsPending] = useState(false)
19
+
20
+ const {
21
+ navigate,
22
+ hooks: { useSession },
23
+ onSessionChange
24
+ } = useContext(AuthUIContext)
25
+
26
+ const { refetch: refetchSession } = useSession()
27
+
28
+ const onSuccess = useCallback(async () => {
29
+ setIsPending(true)
30
+
31
+ await refetchSession?.()
32
+
33
+ if (onSessionChange) await onSessionChange()
34
+
35
+ setIsPending(false)
36
+
37
+ navigate(getRedirectTo())
38
+ }, [refetchSession, onSessionChange, navigate, getRedirectTo])
39
+
40
+ return { onSuccess, isPending }
41
+ }
@@ -0,0 +1,39 @@
1
+ import { useEffect, useState } from "react"
2
+
3
+ export function useTheme() {
4
+ const [theme, setTheme] = useState<"light" | "dark">("light")
5
+
6
+ useEffect(() => {
7
+ const checkTheme = () => {
8
+ const isDark =
9
+ document.documentElement.classList.contains("dark") ||
10
+ document.documentElement
11
+ .getAttribute("style")
12
+ ?.includes("color-scheme: dark")
13
+ setTheme(isDark ? "dark" : "light")
14
+ }
15
+
16
+ // Initial check
17
+ checkTheme()
18
+
19
+ // Listen for changes to html tag
20
+ const observer = new MutationObserver((mutations) => {
21
+ for (const mutation of mutations) {
22
+ if (
23
+ mutation.attributeName === "style" ||
24
+ mutation.attributeName === "class"
25
+ ) {
26
+ checkTheme()
27
+ }
28
+ }
29
+ })
30
+
31
+ observer.observe(document.documentElement, { attributes: true })
32
+
33
+ return () => {
34
+ observer.disconnect()
35
+ }
36
+ }, [])
37
+
38
+ return { theme }
39
+ }
@@ -0,0 +1,46 @@
1
+ // Auth forms (ALL connection types)
2
+ export * from "./components/auth/auth-callback"
3
+ export * from "./components/auth/auth-form"
4
+ export * from "./components/auth/auth-view"
5
+ export * from "./components/auth/forms/email-otp-form"
6
+ export * from "./components/auth/forms/email-verification-form"
7
+ export * from "./components/auth/forms/forgot-password-form"
8
+ export * from "./components/auth/forms/magic-link-form"
9
+ export * from "./components/auth/forms/recover-account-form"
10
+ export * from "./components/auth/forms/reset-password-form"
11
+ export * from "./components/auth/forms/sign-in-form"
12
+ export * from "./components/auth/forms/sign-up-form"
13
+ export * from "./components/auth/forms/two-factor-form"
14
+ export * from "./components/auth/sign-out"
15
+
16
+ // Auth buttons (Social, Magic Link, Email OTP, Passkey, Web3)
17
+ export * from "./components/auth/provider-button"
18
+ export * from "./components/auth/magic-link-button"
19
+ export * from "./components/auth/email-otp-button"
20
+ export * from "./components/auth/passkey-button"
21
+ export * from "./components/auth/wallet-button"
22
+ export * from "./components/auth/one-tap"
23
+ export * from "./components/auth/otp-input-group"
24
+
25
+ // Shared
26
+ export * from "./components/auth-loading"
27
+ export * from "./components/password-input"
28
+ export * from "./components/provider-icons"
29
+ export * from "./components/redirect-to-sign-in"
30
+ export * from "./components/redirect-to-sign-up"
31
+ export * from "./components/signed-in"
32
+ export * from "./components/signed-out"
33
+ export * from "./components/user-avatar"
34
+
35
+ // Hooks & Provider
36
+ export * from "./hooks/use-auth-data"
37
+ export * from "./hooks/use-authenticate"
38
+ export * from "./lib/auth-ui-provider"
39
+ export { AuthUIProvider as AuthProvider } from "./lib/auth-ui-provider"
40
+ export { AuthView as AuthCard } from "./components/auth/auth-view"
41
+ export * from "./lib/social-providers"
42
+ export { getViewByPath } from "./lib/utils"
43
+ export * from "./lib/view-paths"
44
+ export * from "./localization/auth-localization"
45
+ export * from "./types/auth-hooks"
46
+ export * from "./types/auth-mutators"
@@ -0,0 +1 @@
1
+ export * from "./lib/instantdb/use-instant-options"
@@ -0,0 +1,90 @@
1
+ type CacheEntry<T> = {
2
+ data: T | null
3
+ timestamp: number
4
+ isRefetching: boolean
5
+ }
6
+
7
+ class AuthDataCache {
8
+ private cache = new Map<string, CacheEntry<unknown>>()
9
+ private listeners = new Map<string, Set<() => void>>()
10
+ private inFlightRequests = new Map<string, Promise<unknown>>()
11
+
12
+ get<T>(key: string): CacheEntry<T> | undefined {
13
+ return this.cache.get(key) as CacheEntry<T> | undefined
14
+ }
15
+
16
+ set<T>(key: string, data: T | null) {
17
+ const entry: CacheEntry<T> = {
18
+ data,
19
+ timestamp: Date.now(),
20
+ isRefetching: false
21
+ }
22
+ this.cache.set(key, entry)
23
+ this.notify(key)
24
+ }
25
+
26
+ setRefetching(key: string, isRefetching: boolean) {
27
+ const entry = this.cache.get(key)
28
+ if (entry) {
29
+ entry.isRefetching = isRefetching
30
+ this.notify(key)
31
+ }
32
+ }
33
+
34
+ clear(key?: string) {
35
+ if (key) {
36
+ this.cache.delete(key)
37
+ this.inFlightRequests.delete(key)
38
+ this.notify(key)
39
+ } else {
40
+ this.cache.clear()
41
+ this.inFlightRequests.clear()
42
+ const keys = Array.from(this.listeners.keys())
43
+ for (const key of keys) {
44
+ this.notify(key)
45
+ }
46
+ }
47
+ }
48
+
49
+ getInFlightRequest<T>(key: string): Promise<T> | undefined {
50
+ return this.inFlightRequests.get(key) as Promise<T> | undefined
51
+ }
52
+
53
+ setInFlightRequest<T>(key: string, promise: Promise<T>) {
54
+ this.inFlightRequests.set(key, promise)
55
+ }
56
+
57
+ removeInFlightRequest(key: string) {
58
+ this.inFlightRequests.delete(key)
59
+ }
60
+
61
+ subscribe(key: string, callback: () => void) {
62
+ if (!this.listeners.has(key)) {
63
+ this.listeners.set(key, new Set())
64
+ }
65
+ this.listeners.get(key)!.add(callback)
66
+
67
+ return () => {
68
+ const callbacks = this.listeners.get(key)
69
+ if (callbacks) {
70
+ callbacks.delete(callback)
71
+ if (callbacks.size === 0) {
72
+ this.listeners.delete(key)
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+ private notify(key: string) {
79
+ const callbacks = this.listeners.get(key)
80
+ if (callbacks) {
81
+ const callbackArray = Array.from(callbacks)
82
+ for (const callback of callbackArray) {
83
+ callback()
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ // Global singleton instance
90
+ export const authDataCache = new AuthDataCache()