@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.
- package/README.md +239 -306
- package/build/assets/animation/redirect-home.json +1101 -0
- package/build/assets/cross_icon copy.svg +5 -0
- package/build/assets/cross_icon.svg +5 -0
- package/build/assets/gender-diversity.svg +22 -0
- package/build/assets/logo.svg +55 -0
- package/build/assets/okay_icon copy.svg +3 -0
- package/build/assets/okay_icon.svg +3 -0
- package/build/src/api/axiosClient/index.js +5 -0
- package/build/src/api/axiosClient/index.native.js +5 -0
- package/build/src/components/AdvancedTransitionWrapper/index.js +380 -0
- package/build/src/components/AdvancedTransitionWrapper/index.native.js +10 -0
- package/build/src/components/AdvancedTransitionWrapper/types.js +1 -0
- package/build/src/components/ConfirmationModal/index.js +11 -0
- package/build/src/components/ConfirmationModal/index.native.js +15 -0
- package/build/src/components/ConfirmationModal/types.js +1 -0
- package/build/src/components/EmailOTPVerify/index.js +20 -0
- package/build/src/components/EmailOTPVerify/index.native.js +26 -0
- package/build/src/components/EmailOTPVerify/type.js +1 -0
- package/build/src/components/IonIcon/index.js +11 -0
- package/build/src/components/IonIcon/index.native.js +9 -0
- package/build/src/components/IonIcon/types.js +1 -0
- package/build/src/components/OTPStatusLabel/index.js +10 -0
- package/build/src/components/OTPStatusLabel/index.native.js +21 -0
- package/build/src/components/OTPStatusLabel/types.js +1 -0
- package/build/src/components/PasswordCriteria/hooks/usePasswordCriteria.js +78 -0
- package/build/src/components/PasswordCriteria/index.js +47 -0
- package/build/src/components/PasswordCriteria/index.native.js +22 -0
- package/build/src/components/PasswordCriteria/types.js +1 -0
- package/build/src/components/ScreenLayout/index.js +12 -0
- package/build/src/components/ScreenLayout/index.native.js +18 -0
- package/build/src/components/ScreenLayout/types.js +1 -0
- package/build/src/components/SupportDetails/index.js +9 -0
- package/build/src/components/SupportDetails/index.native.js +6 -0
- package/build/src/components/VerifyOTP/index.js +23 -0
- package/build/src/components/VerifyOTP/index.native.js +38 -0
- package/build/src/components/VerifyOTP/types.js +1 -0
- package/build/src/constants/cdn-url/index.js +1 -0
- package/build/src/constants/cdn-url/index.native.js +5 -0
- package/build/src/contexts/AuthContext.js +185 -0
- package/build/src/contexts/type.js +1 -0
- package/build/src/helpers/Network.js +93 -0
- package/build/src/helpers/Validation.js +12 -0
- package/build/src/helpers/show-message/index.js +19 -0
- package/build/src/helpers/show-message/index.native.js +14 -0
- package/build/src/helpers/show-message/types.js +1 -0
- package/build/src/helpers/types.js +1 -0
- package/build/src/hooks/internal/useAuthPackageContext.js +9 -0
- package/build/src/hooks/internal/useTimer.js +40 -0
- package/build/src/hooks/useAuthContext.js +10 -0
- package/build/src/hooks/useRequest.js +41 -0
- package/build/src/index.js +14 -0
- package/build/src/navigator/index.js +10 -0
- package/build/src/navigator/index.native.js +16 -0
- package/build/src/screens/CountryCode/components/CountryCodeDropdown/index.js +38 -0
- package/build/src/screens/CountryCode/components/CountryCodeDropdown/index.native.js +6 -0
- package/build/src/screens/CountryCode/components/CountryCodeDropdown/types.js +1 -0
- package/build/src/screens/CountryCode/hooks/internal/useCountryCode.js +38 -0
- package/build/src/screens/CountryCode/index.js +10 -0
- package/build/src/screens/CountryCode/index.native.js +37 -0
- package/build/src/screens/CountryCode/type.js +1 -0
- package/build/src/screens/CreatePassword/hooks/internal/useCreatePassword.js +52 -0
- package/build/src/screens/CreatePassword/index.js +43 -0
- package/build/src/screens/CreatePassword/index.native.js +32 -0
- package/build/src/screens/CreatePassword/type.js +1 -0
- package/build/src/screens/EnterEmail/hooks/internal/useEnterEmail.js +86 -0
- package/build/src/screens/EnterEmail/index.js +30 -0
- package/build/src/screens/EnterEmail/index.native.js +34 -0
- package/build/src/screens/EnterPassword/hooks/internal/useEnterPassword.js +47 -0
- package/build/src/screens/EnterPassword/index.js +22 -0
- package/build/src/screens/EnterPassword/index.native.js +23 -0
- package/build/src/screens/EnterPassword/types.js +1 -0
- package/build/src/screens/Login/components/LoginWebComponent/index.js +44 -0
- package/build/src/screens/Login/components/LoginWebComponent/index.native.js +6 -0
- package/build/src/screens/Login/index.js +10 -0
- package/build/src/screens/Login/index.native.js +6 -0
- package/build/src/screens/SignUp/components/SignUpForm/index.js +174 -0
- package/build/src/screens/SignUp/components/SignUpForm/index.native.js +6 -0
- package/build/src/screens/SignUp/components/SignUpForm/type.js +1 -0
- package/build/src/screens/SignUp/components/SignUpWebComponent/index.js +82 -0
- package/build/src/screens/SignUp/components/SignUpWebComponent/index.native.js +6 -0
- package/build/src/screens/SignUp/components/SignUpWebComponent/types.js +1 -0
- package/build/src/screens/SignUp/hooks/internal/useSignUp.js +138 -0
- package/build/src/screens/SignUp/index.js +6 -0
- package/build/src/screens/SignUp/index.native.js +185 -0
- package/build/src/screens/SignUp/types.js +1 -0
- package/build/src/screens/UserConsent/hooks/internal/useConsent.js +48 -0
- package/build/src/screens/UserConsent/index.js +69 -0
- package/build/src/screens/UserConsent/index.native.js +46 -0
- package/build/src/screens/UserConsent/types.js +1 -0
- package/build/src/screens/VerifyEmail/hooks/internal/useVerifyEmail.js +69 -0
- package/build/src/screens/VerifyEmail/index.js +8 -0
- package/build/src/screens/VerifyEmail/index.native.js +14 -0
- package/build/src/screens/VerifyEmail/types.js +1 -0
- package/build/src/screens/VerifyMobile/hooks/internal/useVerifyMobile.js +73 -0
- package/build/src/screens/VerifyMobile/index.js +8 -0
- package/build/src/screens/VerifyMobile/index.native.js +9 -0
- package/build/src/screens/VerifyMobile/types.js +1 -0
- package/build/src/screens/Welcome/hooks/internal/useWelcome.js +21 -0
- package/build/src/screens/Welcome/index.js +28 -0
- package/build/src/screens/Welcome/index.native.js +41 -0
- package/build/src/types/types.js +1 -0
- package/build/types/api/axiosClient/index.d.ts +1 -0
- package/build/types/api/axiosClient/index.native.d.ts +1 -0
- package/build/types/components/AdvancedTransitionWrapper/index.d.ts +3 -0
- package/build/types/components/AdvancedTransitionWrapper/index.native.d.ts +5 -0
- package/build/types/components/AdvancedTransitionWrapper/types.d.ts +25 -0
- package/build/types/components/ConfirmationModal/index.d.ts +3 -0
- package/build/types/components/ConfirmationModal/index.native.d.ts +3 -0
- package/build/types/components/ConfirmationModal/types.d.ts +13 -0
- package/build/types/components/EmailOTPVerify/index.d.ts +3 -0
- package/build/types/components/EmailOTPVerify/index.native.d.ts +3 -0
- package/build/types/components/EmailOTPVerify/type.d.ts +9 -0
- package/build/types/components/IonIcon/index.d.ts +3 -0
- package/build/types/components/IonIcon/index.native.d.ts +4 -0
- package/build/types/components/IonIcon/types.d.ts +6 -0
- package/build/types/components/OTPStatusLabel/index.d.ts +2 -0
- package/build/types/components/OTPStatusLabel/index.native.d.ts +3 -0
- package/build/types/components/OTPStatusLabel/types.d.ts +6 -0
- package/build/types/components/PasswordCriteria/hooks/usePasswordCriteria.d.ts +13 -0
- package/build/types/components/PasswordCriteria/index.d.ts +3 -0
- package/build/types/components/PasswordCriteria/index.native.d.ts +3 -0
- package/build/types/components/PasswordCriteria/types.d.ts +15 -0
- package/build/types/components/ScreenLayout/index.d.ts +3 -0
- package/build/types/components/ScreenLayout/index.native.d.ts +3 -0
- package/build/types/components/ScreenLayout/types.d.ts +12 -0
- package/build/types/components/SupportDetails/index.d.ts +2 -0
- package/build/types/components/SupportDetails/index.native.d.ts +2 -0
- package/build/types/components/VerifyOTP/index.d.ts +3 -0
- package/build/types/components/VerifyOTP/index.native.d.ts +3 -0
- package/build/types/components/VerifyOTP/types.d.ts +10 -0
- package/build/types/constants/cdn-url/index.d.ts +1 -0
- package/build/types/constants/cdn-url/index.native.d.ts +3 -0
- package/build/types/contexts/AuthContext.d.ts +36 -0
- package/build/types/contexts/type.d.ts +59 -0
- package/build/types/helpers/Network.d.ts +5 -0
- package/build/types/helpers/Validation.d.ts +2 -0
- package/build/types/helpers/show-message/index.d.ts +3 -0
- package/build/types/helpers/show-message/index.native.d.ts +3 -0
- package/build/types/helpers/show-message/types.d.ts +2 -0
- package/build/types/helpers/types.d.ts +13 -0
- package/build/types/hooks/internal/useAuthPackageContext.d.ts +1 -0
- package/build/types/hooks/internal/useTimer.d.ts +3 -0
- package/build/types/hooks/useAuthContext.d.ts +2 -0
- package/build/types/hooks/useRequest.d.ts +5 -0
- package/build/types/index.d.ts +9 -0
- package/build/types/navigator/index.d.ts +2 -0
- package/build/types/navigator/index.native.d.ts +36 -0
- package/build/types/screens/CountryCode/components/CountryCodeDropdown/index.d.ts +3 -0
- package/build/types/screens/CountryCode/components/CountryCodeDropdown/index.native.d.ts +2 -0
- package/build/types/screens/CountryCode/components/CountryCodeDropdown/types.d.ts +17 -0
- package/build/types/screens/CountryCode/hooks/internal/useCountryCode.d.ts +12 -0
- package/build/types/screens/CountryCode/index.d.ts +2 -0
- package/build/types/screens/CountryCode/index.native.d.ts +2 -0
- package/build/types/screens/CountryCode/type.d.ts +11 -0
- package/build/types/screens/CreatePassword/hooks/internal/useCreatePassword.d.ts +26 -0
- package/build/types/screens/CreatePassword/index.d.ts +3 -0
- package/build/types/screens/CreatePassword/index.native.d.ts +4 -0
- package/build/types/screens/CreatePassword/type.d.ts +43 -0
- package/build/types/screens/EnterEmail/hooks/internal/useEnterEmail.d.ts +24 -0
- package/build/types/screens/EnterEmail/index.d.ts +7 -0
- package/build/types/screens/EnterEmail/index.native.d.ts +4 -0
- package/build/types/screens/EnterPassword/hooks/internal/useEnterPassword.d.ts +20 -0
- package/build/types/screens/EnterPassword/index.d.ts +3 -0
- package/build/types/screens/EnterPassword/index.native.d.ts +4 -0
- package/build/types/screens/EnterPassword/types.d.ts +5 -0
- package/build/types/screens/Login/components/LoginWebComponent/index.d.ts +2 -0
- package/build/types/screens/Login/components/LoginWebComponent/index.native.d.ts +2 -0
- package/build/types/screens/Login/index.d.ts +2 -0
- package/build/types/screens/Login/index.native.d.ts +2 -0
- package/build/types/screens/SignUp/components/SignUpForm/index.d.ts +3 -0
- package/build/types/screens/SignUp/components/SignUpForm/index.native.d.ts +2 -0
- package/build/types/screens/SignUp/components/SignUpForm/type.d.ts +9 -0
- package/build/types/screens/SignUp/components/SignUpWebComponent/index.d.ts +2 -0
- package/build/types/screens/SignUp/components/SignUpWebComponent/index.native.d.ts +2 -0
- package/build/types/screens/SignUp/components/SignUpWebComponent/types.d.ts +24 -0
- package/build/types/screens/SignUp/hooks/internal/useSignUp.d.ts +50 -0
- package/build/types/screens/SignUp/index.d.ts +2 -0
- package/build/types/screens/SignUp/index.native.d.ts +4 -0
- package/build/types/screens/SignUp/types.d.ts +18 -0
- package/build/types/screens/UserConsent/hooks/internal/useConsent.d.ts +10 -0
- package/build/types/screens/UserConsent/index.d.ts +3 -0
- package/build/types/screens/UserConsent/index.native.d.ts +4 -0
- package/build/types/screens/UserConsent/types.d.ts +27 -0
- package/build/types/screens/VerifyEmail/hooks/internal/useVerifyEmail.d.ts +19 -0
- package/build/types/screens/VerifyEmail/index.d.ts +3 -0
- package/build/types/screens/VerifyEmail/index.native.d.ts +4 -0
- package/build/types/screens/VerifyEmail/types.d.ts +8 -0
- package/build/types/screens/VerifyMobile/hooks/internal/useVerifyMobile.d.ts +14 -0
- package/build/types/screens/VerifyMobile/index.d.ts +3 -0
- package/build/types/screens/VerifyMobile/index.native.d.ts +4 -0
- package/build/types/screens/VerifyMobile/types.d.ts +5 -0
- package/build/types/screens/Welcome/hooks/internal/useWelcome.d.ts +14 -0
- package/build/types/screens/Welcome/index.d.ts +4 -0
- package/build/types/screens/Welcome/index.native.d.ts +4 -0
- package/build/types/types/types.d.ts +90 -0
- package/get-metro-config.js +40 -0
- package/get-next-config.js +26 -0
- package/package.json +86 -38
- package/dist/index.esm.js +0 -2028
- package/dist/index.umd.js +0 -70
- package/dist/vite.svg +0 -1
package/README.md
CHANGED
|
@@ -1,343 +1,276 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @truworth/twc-auth
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Truworth Auth Module - A comprehensive authentication solution for React Native and Web applications.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
158
|
+
#### React Native
|
|
94
159
|
|
|
95
|
-
|
|
160
|
+
Copy [`get-metro-config.js`](./get-metro-config.js) in your main project
|
|
96
161
|
|
|
97
|
-
|
|
162
|
+
Import `getMetroConfig` from `get-metro-config.js` and use it to merge with your project's metro config
|
|
98
163
|
|
|
99
|
-
```
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
##
|
|
140
|
-
|
|
141
|
-
### Building the Package
|
|
142
|
-
|
|
143
|
-
```bash
|
|
144
|
-
npm run build
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Linking for Local Development
|
|
201
|
+
## Usage
|
|
148
202
|
|
|
149
|
-
|
|
150
|
-
# In the auth package directory
|
|
151
|
-
npm link
|
|
203
|
+
### React Native
|
|
152
204
|
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
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
|
-
|
|
234
|
+
### Web (Next.js)
|
|
176
235
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
-
##
|
|
255
|
+
## API Reference
|
|
317
256
|
|
|
318
|
-
|
|
257
|
+
### Hooks
|
|
258
|
+
|
|
259
|
+
#### `useAuthContext()`
|
|
319
260
|
|
|
320
261
|
```typescript
|
|
321
|
-
|
|
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
|
-
##
|
|
265
|
+
## Troubleshooting
|
|
334
266
|
|
|
335
|
-
|
|
336
|
-
# Development
|
|
337
|
-
npm run dev # Start dev server
|
|
338
|
-
npm run build # Build package
|
|
267
|
+
### Common Issues
|
|
339
268
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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.
|