@truworth/twc-auth 1.1.0 → 1.2.2

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 (202) hide show
  1. package/README.md +239 -306
  2. package/build/assets/animation/redirect-home.json +1101 -0
  3. package/build/assets/cross_icon copy.svg +5 -0
  4. package/build/assets/cross_icon.svg +5 -0
  5. package/build/assets/gender-diversity.svg +22 -0
  6. package/build/assets/logo.svg +55 -0
  7. package/build/assets/okay_icon copy.svg +3 -0
  8. package/build/assets/okay_icon.svg +3 -0
  9. package/build/src/api/axiosClient/index.js +5 -0
  10. package/build/src/api/axiosClient/index.native.js +5 -0
  11. package/build/src/components/AdvancedTransitionWrapper/index.js +380 -0
  12. package/build/src/components/AdvancedTransitionWrapper/index.native.js +10 -0
  13. package/build/src/components/AdvancedTransitionWrapper/types.js +1 -0
  14. package/build/src/components/ConfirmationModal/index.js +11 -0
  15. package/build/src/components/ConfirmationModal/index.native.js +15 -0
  16. package/build/src/components/ConfirmationModal/types.js +1 -0
  17. package/build/src/components/EmailOTPVerify/index.js +20 -0
  18. package/build/src/components/EmailOTPVerify/index.native.js +26 -0
  19. package/build/src/components/EmailOTPVerify/type.js +1 -0
  20. package/build/src/components/IonIcon/index.js +11 -0
  21. package/build/src/components/IonIcon/index.native.js +9 -0
  22. package/build/src/components/IonIcon/types.js +1 -0
  23. package/build/src/components/OTPStatusLabel/index.js +10 -0
  24. package/build/src/components/OTPStatusLabel/index.native.js +21 -0
  25. package/build/src/components/OTPStatusLabel/types.js +1 -0
  26. package/build/src/components/PasswordCriteria/hooks/usePasswordCriteria.js +78 -0
  27. package/build/src/components/PasswordCriteria/index.js +47 -0
  28. package/build/src/components/PasswordCriteria/index.native.js +22 -0
  29. package/build/src/components/PasswordCriteria/types.js +1 -0
  30. package/build/src/components/ScreenLayout/index.js +12 -0
  31. package/build/src/components/ScreenLayout/index.native.js +18 -0
  32. package/build/src/components/ScreenLayout/types.js +1 -0
  33. package/build/src/components/SupportDetails/index.js +9 -0
  34. package/build/src/components/SupportDetails/index.native.js +6 -0
  35. package/build/src/components/VerifyOTP/index.js +23 -0
  36. package/build/src/components/VerifyOTP/index.native.js +38 -0
  37. package/build/src/components/VerifyOTP/types.js +1 -0
  38. package/build/src/constants/cdn-url/index.js +1 -0
  39. package/build/src/constants/cdn-url/index.native.js +5 -0
  40. package/build/src/contexts/AuthContext.js +185 -0
  41. package/build/src/contexts/type.js +1 -0
  42. package/build/src/helpers/Network.js +93 -0
  43. package/build/src/helpers/Validation.js +12 -0
  44. package/build/src/helpers/show-message/index.js +19 -0
  45. package/build/src/helpers/show-message/index.native.js +14 -0
  46. package/build/src/helpers/show-message/types.js +1 -0
  47. package/build/src/helpers/types.js +1 -0
  48. package/build/src/hooks/internal/useAuthPackageContext.js +9 -0
  49. package/build/src/hooks/internal/useTimer.js +40 -0
  50. package/build/src/hooks/useAuthContext.js +10 -0
  51. package/build/src/hooks/useRequest.js +41 -0
  52. package/build/src/index.js +14 -0
  53. package/build/src/navigator/index.js +10 -0
  54. package/build/src/navigator/index.native.js +16 -0
  55. package/build/src/screens/CountryCode/components/CountryCodeDropdown/index.js +38 -0
  56. package/build/src/screens/CountryCode/components/CountryCodeDropdown/index.native.js +6 -0
  57. package/build/src/screens/CountryCode/components/CountryCodeDropdown/types.js +1 -0
  58. package/build/src/screens/CountryCode/hooks/internal/useCountryCode.js +38 -0
  59. package/build/src/screens/CountryCode/index.js +10 -0
  60. package/build/src/screens/CountryCode/index.native.js +37 -0
  61. package/build/src/screens/CountryCode/type.js +1 -0
  62. package/build/src/screens/CreatePassword/hooks/internal/useCreatePassword.js +52 -0
  63. package/build/src/screens/CreatePassword/index.js +43 -0
  64. package/build/src/screens/CreatePassword/index.native.js +32 -0
  65. package/build/src/screens/CreatePassword/type.js +1 -0
  66. package/build/src/screens/EnterEmail/hooks/internal/useEnterEmail.js +86 -0
  67. package/build/src/screens/EnterEmail/index.js +30 -0
  68. package/build/src/screens/EnterEmail/index.native.js +34 -0
  69. package/build/src/screens/EnterPassword/hooks/internal/useEnterPassword.js +47 -0
  70. package/build/src/screens/EnterPassword/index.js +22 -0
  71. package/build/src/screens/EnterPassword/index.native.js +23 -0
  72. package/build/src/screens/EnterPassword/types.js +1 -0
  73. package/build/src/screens/Login/components/LoginWebComponent/index.js +44 -0
  74. package/build/src/screens/Login/components/LoginWebComponent/index.native.js +6 -0
  75. package/build/src/screens/Login/index.js +10 -0
  76. package/build/src/screens/Login/index.native.js +6 -0
  77. package/build/src/screens/SignUp/components/SignUpForm/index.js +174 -0
  78. package/build/src/screens/SignUp/components/SignUpForm/index.native.js +6 -0
  79. package/build/src/screens/SignUp/components/SignUpForm/type.js +1 -0
  80. package/build/src/screens/SignUp/components/SignUpWebComponent/index.js +82 -0
  81. package/build/src/screens/SignUp/components/SignUpWebComponent/index.native.js +6 -0
  82. package/build/src/screens/SignUp/components/SignUpWebComponent/types.js +1 -0
  83. package/build/src/screens/SignUp/hooks/internal/useSignUp.js +138 -0
  84. package/build/src/screens/SignUp/index.js +6 -0
  85. package/build/src/screens/SignUp/index.native.js +185 -0
  86. package/build/src/screens/SignUp/types.js +1 -0
  87. package/build/src/screens/UserConsent/hooks/internal/useConsent.js +48 -0
  88. package/build/src/screens/UserConsent/index.js +69 -0
  89. package/build/src/screens/UserConsent/index.native.js +46 -0
  90. package/build/src/screens/UserConsent/types.js +1 -0
  91. package/build/src/screens/VerifyEmail/hooks/internal/useVerifyEmail.js +69 -0
  92. package/build/src/screens/VerifyEmail/index.js +8 -0
  93. package/build/src/screens/VerifyEmail/index.native.js +14 -0
  94. package/build/src/screens/VerifyEmail/types.js +1 -0
  95. package/build/src/screens/VerifyMobile/hooks/internal/useVerifyMobile.js +73 -0
  96. package/build/src/screens/VerifyMobile/index.js +8 -0
  97. package/build/src/screens/VerifyMobile/index.native.js +9 -0
  98. package/build/src/screens/VerifyMobile/types.js +1 -0
  99. package/build/src/screens/Welcome/hooks/internal/useWelcome.js +21 -0
  100. package/build/src/screens/Welcome/index.js +28 -0
  101. package/build/src/screens/Welcome/index.native.js +41 -0
  102. package/build/src/types/types.js +1 -0
  103. package/build/types/api/axiosClient/index.d.ts +1 -0
  104. package/build/types/api/axiosClient/index.native.d.ts +1 -0
  105. package/build/types/components/AdvancedTransitionWrapper/index.d.ts +3 -0
  106. package/build/types/components/AdvancedTransitionWrapper/index.native.d.ts +5 -0
  107. package/build/types/components/AdvancedTransitionWrapper/types.d.ts +25 -0
  108. package/build/types/components/ConfirmationModal/index.d.ts +3 -0
  109. package/build/types/components/ConfirmationModal/index.native.d.ts +3 -0
  110. package/build/types/components/ConfirmationModal/types.d.ts +13 -0
  111. package/build/types/components/EmailOTPVerify/index.d.ts +3 -0
  112. package/build/types/components/EmailOTPVerify/index.native.d.ts +3 -0
  113. package/build/types/components/EmailOTPVerify/type.d.ts +9 -0
  114. package/build/types/components/IonIcon/index.d.ts +3 -0
  115. package/build/types/components/IonIcon/index.native.d.ts +4 -0
  116. package/build/types/components/IonIcon/types.d.ts +6 -0
  117. package/build/types/components/OTPStatusLabel/index.d.ts +2 -0
  118. package/build/types/components/OTPStatusLabel/index.native.d.ts +3 -0
  119. package/build/types/components/OTPStatusLabel/types.d.ts +6 -0
  120. package/build/types/components/PasswordCriteria/hooks/usePasswordCriteria.d.ts +13 -0
  121. package/build/types/components/PasswordCriteria/index.d.ts +3 -0
  122. package/build/types/components/PasswordCriteria/index.native.d.ts +3 -0
  123. package/build/types/components/PasswordCriteria/types.d.ts +15 -0
  124. package/build/types/components/ScreenLayout/index.d.ts +3 -0
  125. package/build/types/components/ScreenLayout/index.native.d.ts +3 -0
  126. package/build/types/components/ScreenLayout/types.d.ts +12 -0
  127. package/build/types/components/SupportDetails/index.d.ts +2 -0
  128. package/build/types/components/SupportDetails/index.native.d.ts +2 -0
  129. package/build/types/components/VerifyOTP/index.d.ts +3 -0
  130. package/build/types/components/VerifyOTP/index.native.d.ts +3 -0
  131. package/build/types/components/VerifyOTP/types.d.ts +10 -0
  132. package/build/types/constants/cdn-url/index.d.ts +1 -0
  133. package/build/types/constants/cdn-url/index.native.d.ts +3 -0
  134. package/build/types/contexts/AuthContext.d.ts +36 -0
  135. package/build/types/contexts/type.d.ts +59 -0
  136. package/build/types/helpers/Network.d.ts +5 -0
  137. package/build/types/helpers/Validation.d.ts +2 -0
  138. package/build/types/helpers/show-message/index.d.ts +3 -0
  139. package/build/types/helpers/show-message/index.native.d.ts +3 -0
  140. package/build/types/helpers/show-message/types.d.ts +2 -0
  141. package/build/types/helpers/types.d.ts +13 -0
  142. package/build/types/hooks/internal/useAuthPackageContext.d.ts +1 -0
  143. package/build/types/hooks/internal/useTimer.d.ts +3 -0
  144. package/build/types/hooks/useAuthContext.d.ts +2 -0
  145. package/build/types/hooks/useRequest.d.ts +5 -0
  146. package/build/types/index.d.ts +9 -0
  147. package/build/types/navigator/index.d.ts +2 -0
  148. package/build/types/navigator/index.native.d.ts +36 -0
  149. package/build/types/screens/CountryCode/components/CountryCodeDropdown/index.d.ts +3 -0
  150. package/build/types/screens/CountryCode/components/CountryCodeDropdown/index.native.d.ts +2 -0
  151. package/build/types/screens/CountryCode/components/CountryCodeDropdown/types.d.ts +17 -0
  152. package/build/types/screens/CountryCode/hooks/internal/useCountryCode.d.ts +12 -0
  153. package/build/types/screens/CountryCode/index.d.ts +2 -0
  154. package/build/types/screens/CountryCode/index.native.d.ts +2 -0
  155. package/build/types/screens/CountryCode/type.d.ts +11 -0
  156. package/build/types/screens/CreatePassword/hooks/internal/useCreatePassword.d.ts +26 -0
  157. package/build/types/screens/CreatePassword/index.d.ts +3 -0
  158. package/build/types/screens/CreatePassword/index.native.d.ts +4 -0
  159. package/build/types/screens/CreatePassword/type.d.ts +43 -0
  160. package/build/types/screens/EnterEmail/hooks/internal/useEnterEmail.d.ts +24 -0
  161. package/build/types/screens/EnterEmail/index.d.ts +7 -0
  162. package/build/types/screens/EnterEmail/index.native.d.ts +4 -0
  163. package/build/types/screens/EnterPassword/hooks/internal/useEnterPassword.d.ts +20 -0
  164. package/build/types/screens/EnterPassword/index.d.ts +3 -0
  165. package/build/types/screens/EnterPassword/index.native.d.ts +4 -0
  166. package/build/types/screens/EnterPassword/types.d.ts +5 -0
  167. package/build/types/screens/Login/components/LoginWebComponent/index.d.ts +2 -0
  168. package/build/types/screens/Login/components/LoginWebComponent/index.native.d.ts +2 -0
  169. package/build/types/screens/Login/index.d.ts +2 -0
  170. package/build/types/screens/Login/index.native.d.ts +2 -0
  171. package/build/types/screens/SignUp/components/SignUpForm/index.d.ts +3 -0
  172. package/build/types/screens/SignUp/components/SignUpForm/index.native.d.ts +2 -0
  173. package/build/types/screens/SignUp/components/SignUpForm/type.d.ts +9 -0
  174. package/build/types/screens/SignUp/components/SignUpWebComponent/index.d.ts +2 -0
  175. package/build/types/screens/SignUp/components/SignUpWebComponent/index.native.d.ts +2 -0
  176. package/build/types/screens/SignUp/components/SignUpWebComponent/types.d.ts +24 -0
  177. package/build/types/screens/SignUp/hooks/internal/useSignUp.d.ts +50 -0
  178. package/build/types/screens/SignUp/index.d.ts +2 -0
  179. package/build/types/screens/SignUp/index.native.d.ts +4 -0
  180. package/build/types/screens/SignUp/types.d.ts +18 -0
  181. package/build/types/screens/UserConsent/hooks/internal/useConsent.d.ts +10 -0
  182. package/build/types/screens/UserConsent/index.d.ts +3 -0
  183. package/build/types/screens/UserConsent/index.native.d.ts +4 -0
  184. package/build/types/screens/UserConsent/types.d.ts +27 -0
  185. package/build/types/screens/VerifyEmail/hooks/internal/useVerifyEmail.d.ts +19 -0
  186. package/build/types/screens/VerifyEmail/index.d.ts +3 -0
  187. package/build/types/screens/VerifyEmail/index.native.d.ts +4 -0
  188. package/build/types/screens/VerifyEmail/types.d.ts +8 -0
  189. package/build/types/screens/VerifyMobile/hooks/internal/useVerifyMobile.d.ts +14 -0
  190. package/build/types/screens/VerifyMobile/index.d.ts +3 -0
  191. package/build/types/screens/VerifyMobile/index.native.d.ts +4 -0
  192. package/build/types/screens/VerifyMobile/types.d.ts +5 -0
  193. package/build/types/screens/Welcome/hooks/internal/useWelcome.d.ts +14 -0
  194. package/build/types/screens/Welcome/index.d.ts +4 -0
  195. package/build/types/screens/Welcome/index.native.d.ts +4 -0
  196. package/build/types/types/types.d.ts +90 -0
  197. package/get-metro-config.js +40 -0
  198. package/get-next-config.js +26 -0
  199. package/package.json +86 -38
  200. package/dist/index.esm.js +0 -2028
  201. package/dist/index.umd.js +0 -70
  202. package/dist/vite.svg +0 -1
package/README.md CHANGED
@@ -1,343 +1,276 @@
1
- # TWC Auth Package
1
+ # @truworth/twc-auth
2
2
 
3
- A React authentication package for The Wellness Corner that provides a simple email/password login component with callback-based API integration.
3
+ Truworth Auth Module - A comprehensive authentication solution for React Native and Web applications.
4
4
 
5
- ## Features
5
+ ## Table of Contents
6
6
 
7
- - ✅ Email/password authentication flow
8
- - Two-step verification (email check → password entry)
9
- - ✅ Callback-based API integration
10
- - ✅ TypeScript support
11
- - Lightweight and configurable
12
- - No external dependencies (except React)
7
+ - [Installation](#installation)
8
+ - [React Native](#react-native)
9
+ - [Web](#web)
10
+ - [Development](#development-configure-hot-reloading)
11
+ - [React Native Setup for Hot Reloading](#react-native-setup-for-hot-reloading)
12
+ - [Next.js Setup for Hot Reloading](#nextjs-setup-for-hot-reloading)
13
+ - [Usage](#usage)
14
+ - [API Reference](#api-reference)
15
+ - [Troubleshooting](#troubleshooting)
13
16
 
14
17
  ## Installation
15
18
 
16
- ```bash
17
- npm install @truworth/twc-package-auth
18
- # or
19
- yarn add @truworth/twc-package-auth
19
+ ### React Native
20
+
21
+ 1. Install the package:
22
+
23
+ ```bash
24
+ npm install @truworth/twc-auth
25
+ ```
26
+
27
+ 2. Install peer dependencies:
28
+
29
+ ```bash
30
+ npm install \
31
+ @react-native-community/datetimepicker \
32
+ @react-navigation/native \
33
+ @react-navigation/native-stack \
34
+ @truworth/twc-rn-common \
35
+ @eva-design/eva \
36
+ @ui-kitten/components \
37
+ react-native-gesture-handler \
38
+ react-native-linear-gradient \
39
+ react-native-modalize \
40
+ react-native-reanimated \
41
+ react-native-screens \
42
+ react-native-safe-area-context \
43
+ react-native-svg \
44
+ react-native-vector-icons \
45
+ react@^18.2.0 \
46
+ react-native@^0.74.5
47
+ ```
48
+
49
+ 3. For iOS, install pods:
50
+
51
+ ```bash
52
+ npx pod-install
53
+ ```
54
+
55
+ 4. For React Native Reanimated, follow the [installation steps](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/) if you haven't already.
56
+
57
+ 5. For React Navigation, wrap your app with `NavigationContainer` and ensure you've followed the [getting started guide](https://reactnavigation.org/docs/getting-started/).
58
+
59
+ #### React Native Dependencies
60
+
61
+ | Package | Version |
62
+ | -------------------------------------- | -------- |
63
+ | @react-native-community/datetimepicker | >=8.1.1 |
64
+ | @react-navigation/native | >=6.1.17 |
65
+ | @react-navigation/native-stack | >=6.10.0 |
66
+ | @truworth/twc-rn-common | >=1.0.12 |
67
+ | @ui-kitten/components | >=5.1.2 |
68
+ | @eva-design/eva | >=2.2.0 |
69
+ | lottie-react-native | >=6.7.2 |
70
+ | react | >=18.2.0 |
71
+ | react-native | >=0.74.5 |
72
+ | react-native-fast-image | >=8.6.3 |
73
+ | react-native-freshchat-sdk | >=4.6.6 |
74
+ | react-native-gesture-handler | >=2.16.0 |
75
+ | react-native-linear-gradient | >=2.8.3 |
76
+ | react-native-modalize | >=2.1.1 |
77
+ | react-native-reanimated | >=3.13.0 |
78
+ | react-native-safe-area-context | >=5.3.0 |
79
+ | react-native-screens | >=3.31.1 |
80
+ | react-native-svg | >=15.8.0 |
81
+ | react-native-vector-icons | >=9.2.0 |
82
+
83
+ > Note: lottie-react-native, react-native-fast-image, and react-native-freshchat-sdk are optional and only needed if your app uses features that depend on them.
84
+
85
+ #### Web Dependencies
86
+
87
+ | Package | Version |
88
+ | ------------------------ | -------- |
89
+ | @truworth/twc-web-common | ^1.0.11 |
90
+ | @truworth/twc-web-design | ^1.9.0 |
91
+ | antd | ^5.6.3 |
92
+ | framer-motion | ^12.6.2 |
93
+ | lodash | ^4.17.21 |
94
+ | lucide-react | ^0.483.0 |
95
+ | next | ^15.0.4 |
96
+ | react | ^18.2.0 |
97
+ | react-dom | ^18.2.0 |
98
+
99
+ ### Web
100
+
101
+ 1. Install the package:
102
+
103
+ ```bash
104
+ npm install @truworth/twc-auth
105
+ ```
106
+
107
+ 2. Install peer dependencies:
108
+ ```bash
109
+ npm install \
110
+ next@^15.0.4 \
111
+ @truworth/twc-web-common@^1.0.11 \
112
+ @truworth/twc-web-design@^1.9.0 \
113
+ antd@^5.6.3 \
114
+ framer-motion@^12.6.2 \
115
+ lodash@^4.17.21 \
116
+ lucide-react@^0.483.0 \
117
+ react@^18.2.0 \
118
+ react-dom@^18.2.0
119
+ ```
120
+
121
+ ## Development: Configure Hot Reloading
122
+
123
+ ### React Native Setup for Hot Reloading
124
+
125
+ #### Prerequisites
126
+
127
+ Update main field in `package.json` to `./src/index.tsx`
128
+
129
+ ```diff
130
+ //package.json
131
+ {
132
+ ...
133
+ - "main": "./build/src/index.js"
134
+ + "main": "./src/index.tsx"
135
+ ...
136
+ }
20
137
  ```
21
138
 
22
- ## Usage
23
-
24
- ### Basic Implementation
25
-
26
- ```tsx
27
- import AuthLogin, { type EmailExistsCallback, type LoginSubmitCallback } from '@truworth/twc-package-auth';
28
-
29
- function LoginPage() {
30
- const handleEmailExists: EmailExistsCallback = async (email: string) => {
31
- try {
32
- const response = await fetch('/api/email-exists', {
33
- method: 'POST',
34
- headers: { 'Content-Type': 'application/json' },
35
- body: JSON.stringify({ email })
36
- });
37
-
38
- if (response.ok) {
39
- return { exists: true };
40
- } else if (response.status === 404) {
41
- return { exists: false };
42
- }
43
- throw new Error('Network error');
44
- } catch (error) {
45
- throw error;
46
- }
47
- };
48
-
49
- const handleLogin: LoginSubmitCallback = async (email: string, password: string) => {
50
- const response = await fetch('/api/login', {
51
- method: 'POST',
52
- headers: { 'Content-Type': 'application/json' },
53
- body: JSON.stringify({ email, password })
54
- });
55
-
56
- if (!response.ok) {
57
- throw new Error('Login failed');
58
- }
59
-
60
- const data = await response.json();
61
- return { token: data.token };
62
- };
63
-
64
- const handleSuccess = (token: string) => {
65
- // Handle successful login
66
- localStorage.setItem('token', token);
67
- window.location.href = '/dashboard';
68
- };
69
-
70
- const handleError = (error: any) => {
71
- // Handle errors
72
- if (error.type === 'USER_NOT_FOUND') {
73
- // Redirect to registration
74
- window.location.href = `/register?email=${error.email}`;
75
- } else {
76
- console.error('Login error:', error);
77
- }
78
- };
79
-
80
- return (
81
- <AuthLogin
82
- onEmailExists={handleEmailExists}
83
- onLogin={handleLogin}
84
- onSuccess={handleSuccess}
85
- onError={handleError}
86
- initialEmail=""
87
- className="custom-login-styles"
88
- />
89
- );
139
+ > Note: This change is for local development (hot reloading) only. Before publishing,
140
+ > restore "main" to the built JS (e.g., ./build/src/index.js) or use the "exports" field
141
+ > to map dev vs prod entry points.
142
+
143
+ Add package to your main project's `package.json` file's `dependencies` field
144
+
145
+ ```diff
146
+ //package.json
147
+ {
148
+ ...
149
+ "dependencies": {
150
+ ...
151
+ + "@truworth/twc-auth": "file:relative/path/to/package"
152
+ ...
153
+ }
154
+ ...
90
155
  }
91
156
  ```
92
157
 
93
- ### API Integration
158
+ #### React Native
94
159
 
95
- The package expects two API endpoints:
160
+ Copy [`get-metro-config.js`](./get-metro-config.js) in your main project
96
161
 
97
- #### 1. Email Exists Check (`/api/email-exists`)
162
+ Import `getMetroConfig` from `get-metro-config.js` and use it to merge with your project's metro config
98
163
 
99
- ```typescript
100
- // POST /api/email-exists
101
- // Request: { email: string }
102
- // Response: { exists: boolean, loginType?: number }
103
- // 404 status for non-existent users
104
- ```
105
-
106
- #### 2. Login (`/api/login`)
107
-
108
- ```typescript
109
- // POST /api/login
110
- // Request: { email: string, password: string }
111
- // Response: { token: string }
112
- // 400 status for invalid credentials
164
+ ```diff
165
+ // mainProject/metro.config.js
166
+ + const { getMetroConfig } = require('./get-metro-config')
167
+ + const packageConfig = getMetroConfig(__dirname, 'relative/path/to/package')
168
+ ...
169
+ - module.exports = mergeConfig(defaultConfig, config);
170
+ + module.exports = mergeConfig(defaultConfig, config, packageConfig);
113
171
  ```
114
172
 
115
- ### Props
116
-
117
- | Prop | Type | Required | Description |
118
- |------|------|----------|-------------|
119
- | `onEmailExists` | `EmailExistsCallback` | | Function to check if email exists |
120
- | `onLogin` | `LoginSubmitCallback` | ✅ | Function to handle login |
121
- | `onSuccess` | `(token: string) => void` | ✅ | Callback when login succeeds |
122
- | `onError` | `(error: any) => void` | ❌ | Callback for error handling |
123
- | `initialEmail` | `string` | | Pre-fill email field |
124
- | `className` | `string` | ❌ | Additional CSS classes |
125
-
126
- ### Error Handling
127
-
128
- The package provides structured error handling:
129
-
130
- ```typescript
131
- interface LoginError {
132
- type?: 'USER_NOT_FOUND' | 'INVALID_CREDENTIALS' | 'NETWORK_ERROR';
133
- message: string;
134
- email?: string; // Available for USER_NOT_FOUND errors
135
- redirectToRegistration?: boolean;
173
+ #### Next.js Setup for Hot Reloading
174
+
175
+ Copy [`get-next-config.js`](./get-next-config.js) in your main project
176
+
177
+ Import `getNextConfig` from `get-next-config.js` and use it to merge with your project's next config
178
+
179
+ ```diff
180
+ // mainProject/next.config.js
181
+ + const { getNextConfig } = require('./get-next-config')
182
+ + const packageConfig = getNextConfig(__dirname, 'relative/path/to/package')
183
+ ...
184
+ const nextConfig = {
185
+ ...
186
+ + transpilePackages: [packageConfig.packageName],
187
+ webpack: (config) => {
188
+ ...
189
+ + config.resolve.alias = {
190
+ + ...config.resolve.alias,
191
+ + ...packageConfig.webpackAlias
192
+ + }
193
+ ...
194
+ return config;
195
+ },
136
196
  }
197
+ ...
198
+ module.exports = nextConfig;
137
199
  ```
138
200
 
139
- ## Development
140
-
141
- ### Building the Package
142
-
143
- ```bash
144
- npm run build
145
- ```
146
-
147
- ### Linking for Local Development
201
+ ## Usage
148
202
 
149
- ```bash
150
- # In the auth package directory
151
- npm link
203
+ ### React Native
152
204
 
153
- # In your host application
154
- npm link @truworth/twc-package-auth
155
- ```
205
+ ```tsx
206
+ import React, { useEffect } from "react";
207
+ import { createNativeStackNavigator } from "@react-navigation/native-stack";
208
+ import { NavigationContainer } from "@react-navigation/native";
209
+ import { AuthNavigator, AuthProvider } from "@truworth/twc-auth";
210
+ import type { LoginResponse } from "@truworth/twc-auth";
211
+ import Home from "./screens/Home";
212
+
213
+ const { Navigator, Screen } = createNativeStackNavigator();
214
+
215
+ const ExampleAppNavigator = () => {
216
+ const onLogin = async (result: LoginResponse) => {
217
+ //TODO: Store token in secure storage & redirect to home screen
218
+ };
156
219
 
157
- ### Project Structure
220
+ return (
221
+ <NavigationContainer>
222
+ <AuthProvider onLogin={onLogin}>
223
+ <Navigator screenOptions={{ headerShown: false }}>
224
+ <Screen name="AuthNavigator" component={AuthNavigator} />
225
+ </Navigator>
226
+ </AuthProvider>
227
+ </NavigationContainer>
228
+ );
229
+ };
158
230
 
231
+ export default ExampleAppNavigator;
159
232
  ```
160
- src/
161
- ├── components/
162
- │ └── AuthLogin.tsx # Main login component
163
- ├── types.ts # TypeScript type definitions
164
- └── index.ts # Package exports
165
- ```
166
-
167
- ## Integration Example
168
-
169
- See the complete integration example in the host application:
170
-
171
- - **API Routes**: `pages/api/email-exists.ts` and `pages/api/login.ts`
172
- - **Login Page**: `pages/login.tsx`
173
- - **Index Redirect**: `pages/index.tsx`
174
233
 
175
- ## Migration from Hardcoded Token
234
+ ### Web (Next.js)
176
235
 
177
- The package replaces hardcoded token entry with proper authentication:
178
-
179
- **Before**: Manual token entry via `_enter-token.tsx`
180
- **After**: Email/password login with proper backend integration
181
-
182
- ## Styling
183
-
184
- The component uses minimal inline styles and accepts a `className` prop for customization. Default styles include:
185
-
186
- - Responsive design
187
- - Form validation states
188
- - Loading indicators
189
- - Error messages
190
-
191
- ## License
192
-
193
- Private package for The Wellness Corner internal use.
194
-
195
- # TWC Auth Package Development
196
-
197
- ## Project Overview
198
- A comprehensive authentication package (`@truworth/twc-package-auth`) built for TWC partner integrations. The package provides a complete login/registration UI that can be integrated into host applications.
199
-
200
- ## 🚀 **Current Status: Phase 2 - Complete UI Implementation**
201
-
202
- ### ✅ **Phase 1 Completed:**
203
- - Basic email/password login working
204
- - Token management and auth context integration
205
- - Host app successfully using auth package
206
- - API callback system functional
207
-
208
- ### 🔄 **Phase 2 In Progress:**
209
- Implementing complete production UI from `/Users/soumik.acharjee/twc-repos/twc-v2/pages/login/index.tsx`
210
-
211
- **Features to Implement:**
212
- 1. **Complete LoginForm Component**
213
- - Email validation step with proper UI
214
- - Password entry step with validation
215
- - Back navigation between steps
216
- - Forgot password integration
217
-
218
- 2. **SSO Login Flow**
219
- - Organization search with autocomplete
220
- - SSO initiation and redirect handling
221
- - Multi-step UI with transitions
222
-
223
- 3. **OTP/Mobile Sign-in**
224
- - OTP request and verification
225
- - Mobile number handling
226
- - Modal-based UI flow
227
-
228
- 4. **Password Reset Flow**
229
- - Email-based reset initiation
230
- - OTP verification for reset
231
- - New password setting
232
-
233
- 5. **Enhanced UI/UX**
234
- - Left panel with background image and carousel
235
- - Smooth transitions between states
236
- - Proper loading states and error handling
237
- - Responsive design matching production
238
-
239
- **Excluded Features:**
240
- - ❌ Google Sign-in (removed)
241
- - ❌ Facebook Sign-in (removed)
242
-
243
- ## Architecture Principles
244
-
245
- ### **Pure UI Package with Callbacks**
246
- - Auth package contains ONLY UI components and logic
247
- - ALL API calls handled by host application via callbacks
248
- - No direct API dependencies in the package
249
- - Host app passes callback functions for all backend operations
250
-
251
- ### **Production Reference**
252
- - **Source:** `/Users/soumik.acharjee/twc-repos/twc-v2/pages/login/index.tsx`
253
- - **Target:** `/Users/soumik.acharjee/twc-repos/twc-web-package-host`
254
- - **Design System:** `@truworth/twc-web-design` for exact UI match
255
-
256
- ## Development Tasks Breakdown
257
-
258
- ### **Task 1: Enhanced Types & Interfaces**
259
- - [ ] Update `AuthLoginProps` with all callback functions
260
- - [ ] Add interfaces for SSO, OTP, and Reset Password
261
- - [ ] Define error types for different scenarios
262
-
263
- ### **Task 2: Complete LoginForm Component**
264
- - [ ] Implement two-step email/password flow
265
- - [ ] Add form validation and error states
266
- - [ ] Integrate forgot password trigger
267
-
268
- ### **Task 3: SSO Login Component**
269
- - [ ] Build organization search with autocomplete
270
- - [ ] Create SSO selection and initiation UI
271
- - [ ] Handle SSO redirect flow
272
-
273
- ### **Task 4: OTP/Mobile Sign-in Component**
274
- - [ ] Create modal-based OTP interface
275
- - [ ] Implement OTP request and verification
276
- - [ ] Add mobile number validation
277
-
278
- ### **Task 5: Password Reset Component**
279
- - [ ] Build reset password modal
280
- - [ ] Create OTP verification for reset
281
- - [ ] Add new password setting form
282
-
283
- ### **Task 6: Main Auth Component Integration**
284
- - [ ] Create state management for different flows
285
- - [ ] Implement smooth transitions between states
286
- - [ ] Add comprehensive error handling
287
-
288
- ### **Task 7: Host App Integration**
289
- - [ ] Update login.tsx with all callback handlers
290
- - [ ] Create API route handlers for new endpoints
291
- - [ ] Test complete integration flow
292
-
293
- ## Current Implementation Status
294
-
295
- ```typescript
296
- // Current working callbacks
297
- interface AuthLoginProps {
298
- onEmailExists: (email: string) => void;
299
- onLogin: (email: string, password: string) => void;
300
- onSuccess: (token: string) => void;
301
- onError?: (error: AuthError | any) => void;
302
- makeRequest: (params: MakeRequestParams) => void;
303
- }
236
+ ```tsx
237
+ // pages/_app.tsx
238
+ import { AuthProvider } from "@truworth/twc-auth";
239
+ import type { LoginResponse } from "@truworth/twc-auth";
240
+ import type { AppProps } from "next/app";
241
+
242
+ export default function App({ Component, pageProps }: AppProps) {
243
+ const onLogin = (result: LoginResponse) => {
244
+ //TODO: Store token in secure storage & redirect to home screen
245
+ };
304
246
 
305
- // Next: Expand to include all production features
306
- interface CompleteAuthLoginProps extends AuthLoginProps {
307
- onSSOSearch: (query: string, callback: (results: any[]) => void) => void;
308
- onSSOLogin: (clientId: string, callback: (authUrl: string) => void) => void;
309
- onOTPRequest: (email: string, callback: (success: boolean) => void) => void;
310
- onOTPVerify: (email: string, otp: string, callback: (token: string) => void) => void;
311
- onPasswordReset: (email: string, callback: (success: boolean) => void) => void;
312
- // ... additional callbacks
247
+ return (
248
+ <AuthProvider onLogin={onLogin}>
249
+ <Component {...pageProps} />
250
+ </AuthProvider>
251
+ );
313
252
  }
314
253
  ```
315
254
 
316
- ## Integration Pattern
255
+ ## API Reference
317
256
 
318
- The host app handles all API calls and passes results back to the auth package via callbacks:
257
+ ### Hooks
258
+
259
+ #### `useAuthContext()`
319
260
 
320
261
  ```typescript
321
- // Host app implementation
322
- const handleSSOSearch = (query: string, callback: (results: any[]) => void) => {
323
- makeRequest({
324
- url: '/auth/login-sso/search-clients',
325
- method: 'POST',
326
- data: { query },
327
- onSuccess: (data) => callback(data),
328
- onError: (err) => callback([])
329
- });
330
- };
262
+ const { onLogin, logout, onLaunchAuthSession, LogoComponent } = useAuthContext();
331
263
  ```
332
264
 
333
- ## Build Commands
265
+ ## Troubleshooting
334
266
 
335
- ```bash
336
- # Development
337
- npm run dev # Start dev server
338
- npm run build # Build package
267
+ ### Common Issues
339
268
 
340
- # Integration Testing
341
- cd ../twc-web-package-host
342
- npm run dev # Test complete integration
343
- ```
269
+ 1. **Module not found**
270
+
271
+ - Ensure all peer dependencies are installed
272
+ - Clear Metro bundler cache: `npx react-native start --reset-cache`
273
+ - For Next.js, remove `.next` and restart: `rm -rf .next && next dev`
274
+ - For React Native: Ensure `babel.config.js` includes `plugins: ['react-native-reanimated/plugin']` as the last plugin
275
+ - For Next.js with Babel: Add `plugins: ['react-native-reanimated/plugin']` to your Babel config if using Babel (not needed with default SWC)
276
+ - For iOS CocoaPods issues: First try `cd ios && pod install` or clean the build folder in Xcode. Only use `pod deintegrate` as a last resort if other steps fail.