@truworth/twc-auth 1.2.9 → 1.2.11

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 (23) hide show
  1. package/build/src/contexts/AuthContext.js +1 -1
  2. package/build/src/hooks/useRequest.js +1 -4
  3. package/build/src/screens/CreatePassword/hooks/internal/useCreatePassword.js +2 -2
  4. package/build/src/screens/CreatePassword/index.js +2 -2
  5. package/build/src/screens/CreatePassword/index.native.js +2 -2
  6. package/build/src/screens/EnterPassword/hooks/internal/useEnterPassword.js +3 -1
  7. package/build/src/screens/LoginWithEmailOTP/hooks/internal/useLoginWithEmailOTP.js +1 -3
  8. package/build/src/screens/LoginWithMobileOTP/hooks/internal/useLoginWithMobileOTP.js +2 -1
  9. package/build/src/screens/ResetPassword/hooks/internal/useResetPassword.js +2 -0
  10. package/build/src/screens/ResetPassword/index.js +2 -2
  11. package/build/src/screens/ResetPassword/index.native.js +2 -2
  12. package/build/src/screens/SSOLogin/SSOCallback/hooks/internal/useSSOCallback.js +2 -1
  13. package/build/src/screens/SignUp/components/SignUpForm/index.js +2 -2
  14. package/build/src/screens/UserConsent/index.js +2 -1
  15. package/build/src/screens/UserConsent/index.native.js +2 -1
  16. package/build/src/screens/VerifyLinkPrimaryAccountMobileOTP/hooks/internal/useVerifyLinkPrimaryAccountMobileOTP.js +2 -1
  17. package/build/src/screens/VerifyMobile/hooks/internal/useVerifyMobile.js +2 -1
  18. package/build/src/screens/Welcome/SocialAuth/hooks/useSocialAuth.native.js +5 -9
  19. package/build/src/screens/Welcome/SocialAuth/hooks/web/useFacebookAuth.web.js +3 -5
  20. package/build/src/screens/Welcome/SocialAuth/hooks/web/useGoogleAuth.web.js +3 -5
  21. package/build/types/screens/CreatePassword/hooks/internal/useCreatePassword.d.ts +1 -1
  22. package/build/types/screens/ResetPassword/hooks/internal/useResetPassword.d.ts +1 -0
  23. package/package.json +2 -3
@@ -39,7 +39,7 @@ const AuthProvider = ({ children, LogoComponent, session, appConfig, onLogin, on
39
39
  const [profile, setProfile] = useState(null);
40
40
  const [client, setClient] = useState(null);
41
41
  const [registrationMethod, setRegistrationMethod] = useState(null);
42
- const [token, setToken] = useState('');
42
+ const [token, setToken] = useState(session?.token || '');
43
43
  const [otpValue, setOtpValue] = useState('');
44
44
  const { request } = useMemo(() => createHttpClient({
45
45
  token,
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useMemo, useState } from 'react';
1
+ import { useMemo } from 'react';
2
2
  import { showMessage } from '../helpers/show-message';
3
3
  import { useAuthPackageContext } from './internal/useAuthPackageContext';
4
4
  import { createHttpClient } from '../helpers/network';
@@ -10,9 +10,6 @@ const useRequest = () => {
10
10
  onLogout: async () => logout(),
11
11
  }), [token]);
12
12
  const makeRequest = async ({ url, method, body, onSuccess, onFailure, ...axiosOptions }) => {
13
- if (!token) {
14
- return;
15
- }
16
13
  try {
17
14
  const response = await request({
18
15
  url,
@@ -23,7 +23,7 @@ const useCreatePassword = () => {
23
23
  setConfirmPassword('');
24
24
  onResult();
25
25
  };
26
- const disabled = !Object.keys(criteria).every(c => criteria[c]) || (password !== confirmPassword);
26
+ const isContinueDisabled = !Object.keys(criteria).every(c => criteria[c]) || (password !== confirmPassword);
27
27
  return {
28
28
  password, setPassword,
29
29
  confirmPassword, setConfirmPassword,
@@ -33,7 +33,7 @@ const useCreatePassword = () => {
33
33
  criteria, setCriteria,
34
34
  handlePassword, handleConfirmPassword,
35
35
  handleSkip,
36
- disabled
36
+ isContinueDisabled
37
37
  };
38
38
  };
39
39
  export { useCreatePassword };
@@ -12,12 +12,12 @@ const CreatePassword = ({ userDetails, handleBack, onContinue }) => {
12
12
  }
13
13
  });
14
14
  const { password, confirmPassword } = form.watch();
15
- const { criteria, setCriteria, maxLength, setMaxLength, handleSkip, } = useCreatePassword();
15
+ const { criteria, setCriteria, maxLength, setMaxLength, handleSkip, isContinueDisabled } = useCreatePassword();
16
16
  return (_jsx(ScreenLayout, { title: _jsxs(Flex, { justify: "between", align: "center", children: [_jsx(Typography, { type: "heading", size: "h5", children: "Create your Password" }), countryCode == '91' &&
17
17
  _jsx(Button, { label: "Skip Now", variant: "link", onClick: () => handleSkip({ onResult: onContinue }) })] }), subTitle: "Use a password that's easy to remember and fulfills all the requirements listed below.", buttonProps: {
18
18
  label: 'Continue',
19
19
  onClick: () => onContinue(password, confirmPassword),
20
- disabled: !password || !confirmPassword || (password !== confirmPassword)
20
+ disabled: isContinueDisabled
21
21
  }, onPressBack: handleBack, children: _jsxs(Form, { form: form, className: 'w-full', children: [_jsx(Form.Item, { name: "password", label: "Enter Password", normalize: (value) => value.replace(/\s/g, ''), rules: [
22
22
  {
23
23
  required: true,
@@ -8,14 +8,14 @@ import { PasswordCriteria } from '../../components/PasswordCriteria/index.native
8
8
  const { primary } = Colors;
9
9
  const CreatePassword = ({ navigation, route }) => {
10
10
  const { countryCode, email } = route.params;
11
- const { password, confirmPassword, passwordVisible, setPasswordVisible, confirmPasswordVisible, setConfirmPasswordVisible, maxLength, setMaxLength, criteria, setCriteria, handlePassword, handleConfirmPassword, handleSkip, disabled } = useCreatePassword();
11
+ const { password, confirmPassword, passwordVisible, setPasswordVisible, confirmPasswordVisible, setConfirmPasswordVisible, maxLength, setMaxLength, criteria, setCriteria, handlePassword, handleConfirmPassword, handleSkip, isContinueDisabled } = useCreatePassword();
12
12
  const onContinue = () => {
13
13
  navigation.navigate('UserConsent', { ...route.params, password });
14
14
  };
15
15
  return (_jsx(Layout, { style: { flex: 1, backgroundColor: primary.white }, children: _jsxs(ScreenLayout, { title: "Create your Password", subTitle: "Use a password that\u2019s easy to remember and fulfills all the requirement listed below.", buttonProps: {
16
16
  label: 'Continue',
17
17
  onPress: onContinue,
18
- disabled: disabled,
18
+ disabled: isContinueDisabled,
19
19
  }, accessoryRight: countryCode == '91'
20
20
  ? _jsx(TouchableOpacity, { activeOpacity: 0.8, onPress: () => {
21
21
  Keyboard.dismiss();
@@ -49,7 +49,9 @@ const useEnterPassword = () => {
49
49
  const errorMessage = error?.response?.data?.errors?.[0]?.message;
50
50
  if (error?.response?.status === 400) {
51
51
  setInvalidPassword(true);
52
- showMessage({ message: errorMessage ?? 'Email and password do not match!' });
52
+ if (source === 'web') {
53
+ showMessage({ message: errorMessage ?? 'Email and password do not match!' });
54
+ }
53
55
  return;
54
56
  }
55
57
  showMessage({ message: errorMessage ?? 'Something went wrong. Please try again.' });
@@ -45,9 +45,7 @@ const useLoginWithEmailOTP = ({ email, password, source, sessionToken, mfaEnable
45
45
  }).then((res) => {
46
46
  setStatus('valid');
47
47
  const { token, member } = res.data;
48
- if (token) {
49
- onTokenChange(token);
50
- }
48
+ onTokenChange(token);
51
49
  onLogin({ token, member });
52
50
  }).catch((error) => {
53
51
  const errorCode = error?.response?.status;
@@ -7,7 +7,7 @@ const useLoginWithMobileOTP = ({ phone, email, source }) => {
7
7
  const [timer, setTimer] = useState(180);
8
8
  const [status, setStatus] = useState('timer');
9
9
  const [sessionToken, setSessionToken] = useState('');
10
- const { onLogin } = useAuthPackageContext();
10
+ const { onLogin, onTokenChange } = useAuthPackageContext();
11
11
  useInterval(() => {
12
12
  if (!timer) {
13
13
  return;
@@ -42,6 +42,7 @@ const useLoginWithMobileOTP = ({ phone, email, source }) => {
42
42
  }).then((res) => {
43
43
  setStatus('valid');
44
44
  const { token, member } = res.data;
45
+ onTokenChange(token);
45
46
  onLogin({ token, member });
46
47
  }).catch((error) => {
47
48
  const errorCode = error?.response?.status;
@@ -39,6 +39,7 @@ const useResetPassword = ({ sessionToken }) => {
39
39
  showMessage({ message: err?.response?.data?.errors?.[0]?.message || 'An unexpected error occurred' });
40
40
  }).finally(() => setLoading(false));
41
41
  };
42
+ const isContinueDisabled = !Object.keys(criteria).every(c => criteria[c]) || (password !== confirmPassword);
42
43
  return {
43
44
  loading,
44
45
  password, setPassword,
@@ -50,6 +51,7 @@ const useResetPassword = ({ sessionToken }) => {
50
51
  handlePassword,
51
52
  handleContinue,
52
53
  handleConfirmPassword,
54
+ isContinueDisabled
53
55
  };
54
56
  };
55
57
  export { useResetPassword };
@@ -11,12 +11,12 @@ const ResetPassword = ({ email, sessionToken, onPressBack, onContinue }) => {
11
11
  }
12
12
  });
13
13
  const { password, confirmPassword } = form.watch();
14
- const { loading, criteria, setCriteria, maxLength, setMaxLength, handlePassword, handleConfirmPassword, handleContinue, } = useResetPassword({ sessionToken });
14
+ const { loading, criteria, setCriteria, maxLength, setMaxLength, handlePassword, handleConfirmPassword, handleContinue, isContinueDisabled } = useResetPassword({ sessionToken });
15
15
  return (_jsx(ScreenLayout, { title: "Reset your Password", subTitle: "Use a password that\u2019s easy to remember and fulfills all the requirements listed below.", buttonProps: {
16
16
  loading,
17
17
  label: 'Continue',
18
18
  onClick: () => handleContinue({ onResult: onContinue }),
19
- disabled: !password || !confirmPassword || (password !== confirmPassword)
19
+ disabled: isContinueDisabled
20
20
  }, onPressBack: onPressBack, children: _jsx(Flex, { direction: "column", children: _jsxs(Form, { form: form, className: "w-full", children: [_jsx(Form.Item, { label: "Enter Password", normalize: (value) => value.replace(/\s/g, ''), rules: [
21
21
  {
22
22
  required: true,
@@ -7,7 +7,7 @@ import { PasswordCriteria } from '../../components/PasswordCriteria/index.native
7
7
  const { primary } = Colors;
8
8
  const ResetPassword = ({ navigation, route }) => {
9
9
  const { sessionToken, email } = route.params || {};
10
- const { loading, password, confirmPassword, passwordVisible, setPasswordVisible, confirmPasswordVisible, setConfirmPasswordVisible, maxLength, setMaxLength, criteria, setCriteria, handlePassword, handleContinue, handleConfirmPassword, } = useResetPassword({ sessionToken });
10
+ const { loading, password, confirmPassword, passwordVisible, setPasswordVisible, confirmPasswordVisible, setConfirmPasswordVisible, maxLength, setMaxLength, criteria, setCriteria, handlePassword, handleContinue, handleConfirmPassword, isContinueDisabled } = useResetPassword({ sessionToken });
11
11
  return (_jsx(Layout, { style: { flex: 1, backgroundColor: primary.white }, children: _jsxs(ScreenLayout, { title: "Reset your Password", subTitle: "Use a password that\u2019s easy to remember and fulfills all the requirements listed below.", buttonProps: {
12
12
  loading,
13
13
  label: 'Continue',
@@ -16,7 +16,7 @@ const ResetPassword = ({ navigation, route }) => {
16
16
  onResult: () => navigation.navigate('EnterEmail')
17
17
  });
18
18
  },
19
- disabled: !Object.keys(criteria).every(c => criteria[c]) || (password !== confirmPassword),
19
+ disabled: isContinueDisabled
20
20
  }, children: [_jsx(TextInputField, { placeholder: "Enter password...", onChangeValue: handlePassword, secureTextEntry: !passwordVisible, value: password, rightIcon2: passwordVisible
21
21
  ? 'eye-outline'
22
22
  : 'eye-off-outline', onPressRightIcon2: () => setPasswordVisible(!passwordVisible), autoFocus: true, maxLength: maxLength }), _jsx(PasswordCriteria, { email: email, criteria: criteria, onCriteriaChange: setCriteria, onMaxLengthChange: setMaxLength, password: password }), _jsx(TextInputField, { placeholder: "Confirm password...", onChangeValue: handleConfirmPassword, secureTextEntry: !confirmPasswordVisible, value: confirmPassword, rightIcon2: confirmPasswordVisible
@@ -11,7 +11,7 @@ import { RegistrationMethod } from "../../../../../enums";
11
11
  const useSSOCallback = ({ clientId, code }) => {
12
12
  const [error, setError] = useState(null);
13
13
  const [result, setResult] = useState(null);
14
- const { onLogin, onRegistrationMethodChange } = useAuthPackageContext();
14
+ const { onLogin, onRegistrationMethodChange, onTokenChange } = useAuthPackageContext();
15
15
  const processOAuthCallback = useCallback((code) => {
16
16
  setError(null);
17
17
  axiosClient({
@@ -24,6 +24,7 @@ const useSSOCallback = ({ clientId, code }) => {
24
24
  setResult(res.data);
25
25
  }
26
26
  else {
27
+ onTokenChange(res?.data?.token);
27
28
  return onLogin({ token: res?.data?.token, member: res?.data?.member });
28
29
  }
29
30
  }).catch((error) => {
@@ -27,8 +27,8 @@ const SignUpFormComponent = ({ userDetails, onContinue }) => {
27
27
  const form = useForm({
28
28
  liveValidation: true,
29
29
  defaultValues: {
30
- firstName: userDetails.firstName ?? "",
31
- lastName: userDetails.lastName ?? "",
30
+ firstName: userDetails.firstName ?? getQueryParam(router.query.firstName),
31
+ lastName: userDetails.lastName ?? getQueryParam(router.query.lastName),
32
32
  dateOfBirth: userDetails.selectedDOB,
33
33
  email: userDetails.email ?? "",
34
34
  phone: userDetails.phone ?? "",
@@ -20,11 +20,12 @@ const UserConsent = ({ userDetails, handleBack }) => {
20
20
  const [showVerifyMobileModal, setShowVerifyMobileModal] = useState(false);
21
21
  const [showVerifyEmailModal, setShowVerifyEmailModal] = useState(false);
22
22
  const [sessionToken, setSessionToken] = useState('');
23
- const { onLogin, appConfig: { appName, privacyPolicyUrl }, LogoComponent } = useAuthPackageContext();
23
+ const { onLogin, appConfig: { appName, privacyPolicyUrl }, LogoComponent, onTokenChange } = useAuthPackageContext();
24
24
  const { loading, onAgree } = useConsent();
25
25
  const onAgreeHandler = (res) => {
26
26
  const { token, member, emailVerificationRequired, mobileVerificationRequired, sessionToken } = res;
27
27
  if (token && member) {
28
+ onTokenChange(token);
28
29
  return onLogin({ token, member });
29
30
  }
30
31
  if (emailVerificationRequired) {
@@ -8,11 +8,12 @@ import { useConsent } from './hooks/internal/useConsent';
8
8
  const { primary, gray } = Colors;
9
9
  const UserConsent = ({ navigation, route }) => {
10
10
  const { email, phone } = route.params || {};
11
- const { onLogin, appConfig: { appName, privacyPolicyUrl } } = useAuthPackageContext();
11
+ const { onLogin, appConfig: { appName, privacyPolicyUrl }, onTokenChange } = useAuthPackageContext();
12
12
  const { loading, onAgree } = useConsent();
13
13
  const onAgreeHandler = (res) => {
14
14
  const { token, member, emailVerificationRequired, mobileVerificationRequired, sessionToken } = res;
15
15
  if (token && member) {
16
+ onTokenChange(token);
16
17
  return onLogin({ token, member });
17
18
  }
18
19
  if (emailVerificationRequired) {
@@ -12,7 +12,7 @@ const initialTimer = 180;
12
12
  const useVerifyLinkPrimaryAccountMobileOTP = ({ sessionToken }) => {
13
13
  const [status, setStatus] = useState('timer');
14
14
  const [timer, setTimer] = useState(initialTimer);
15
- const { onLogin } = useAuthPackageContext();
15
+ const { onLogin, onTokenChange } = useAuthPackageContext();
16
16
  const invalidTimerRef = useRef(null);
17
17
  const sessionTokenRef = useRef(sessionToken);
18
18
  useInterval(() => {
@@ -47,6 +47,7 @@ const useVerifyLinkPrimaryAccountMobileOTP = ({ sessionToken }) => {
47
47
  }).then((res) => {
48
48
  const { token, member } = res.data;
49
49
  setStatus('valid');
50
+ onTokenChange(token);
50
51
  onLogin({ token, member });
51
52
  }).catch((err) => {
52
53
  if (err?.response?.status === 400) {
@@ -13,7 +13,7 @@ const useVerifyMobile = ({ sessionToken }) => {
13
13
  const [sessionTokenState, setSessionToken] = useState(sessionToken || '');
14
14
  const [timer, setTimer] = useState(initialTimer);
15
15
  const [status, setStatus] = useState('timer');
16
- const { onLogin } = useAuthPackageContext();
16
+ const { onLogin, onTokenChange } = useAuthPackageContext();
17
17
  useEffect(() => {
18
18
  resendOTP();
19
19
  }, []);
@@ -48,6 +48,7 @@ const useVerifyMobile = ({ sessionToken }) => {
48
48
  data: { otp, sessionToken: sessionTokenState },
49
49
  }).then((res) => {
50
50
  const { token, member } = res.data;
51
+ onTokenChange(token);
51
52
  onLogin({ token, member });
52
53
  setStatus('valid');
53
54
  }).catch((err) => {
@@ -11,7 +11,7 @@ import appleAuth from '@invertase/react-native-apple-authentication';
11
11
  import { axiosClient } from "../../../../api/axiosClient";
12
12
  const useSocialAuth = () => {
13
13
  const [loading, setLoading] = useState(false);
14
- const { onLogin, socialLoginConfig, onRegistrationMethodChange } = useAuthPackageContext();
14
+ const { onLogin, socialLoginConfig, onRegistrationMethodChange, onTokenChange } = useAuthPackageContext();
15
15
  const navigation = useNavigation();
16
16
  const googleAppId = socialLoginConfig?.google?.webClientId;
17
17
  const loginWithGoogle = useCallback(async () => {
@@ -107,10 +107,8 @@ const useSocialAuth = () => {
107
107
  token: appleAuthResponse.identityToken,
108
108
  source: Platform.OS,
109
109
  });
110
- onLogin({
111
- token: data.token,
112
- member: data.member
113
- });
110
+ onTokenChange(data.token);
111
+ onLogin({ token: data.token, member: data.member });
114
112
  return;
115
113
  }
116
114
  catch (error) {
@@ -174,10 +172,8 @@ const useSocialAuth = () => {
174
172
  type: 'error'
175
173
  });
176
174
  case SocialAuthStatus.SUCCESS:
177
- onLogin({
178
- token: result.data.token,
179
- member: result.data.member
180
- });
175
+ onTokenChange(result.data.token);
176
+ onLogin({ token: result.data.token, member: result.data.member });
181
177
  break;
182
178
  }
183
179
  };
@@ -6,7 +6,7 @@ import { handleFacebookAuth } from "../../commonSocialAuth";
6
6
  import { showMessage } from "../../../../../helpers/show-message";
7
7
  export const useFacebookAuth = () => {
8
8
  const [error, setError] = useState(null);
9
- const { onLogin, socialLoginConfig, onRegistrationMethodChange } = useAuthPackageContext();
9
+ const { onLogin, socialLoginConfig, onRegistrationMethodChange, onTokenChange } = useAuthPackageContext();
10
10
  const router = useRouter();
11
11
  const facebookAppId = socialLoginConfig?.facebook?.webClientId;
12
12
  // Load Facebook SDK once
@@ -95,10 +95,8 @@ export const useFacebookAuth = () => {
95
95
  type: "error",
96
96
  });
97
97
  case "SUCCESS":
98
- onLogin({
99
- token: result.data.token,
100
- member: result.data.member
101
- });
98
+ onTokenChange(result.data.token);
99
+ onLogin({ token: result.data.token, member: result.data.member });
102
100
  break;
103
101
  }
104
102
  });
@@ -7,7 +7,7 @@ import { useRouter } from "next/router";
7
7
  import { handleGoogleAuth } from "../../commonSocialAuth";
8
8
  export const useGoogleAuth = () => {
9
9
  const router = useRouter();
10
- const { onLogin, socialLoginConfig, onRegistrationMethodChange } = useAuthPackageContext();
10
+ const { onLogin, socialLoginConfig, onRegistrationMethodChange, onTokenChange } = useAuthPackageContext();
11
11
  const googleAppId = socialLoginConfig?.google?.webClientId;
12
12
  const onSuccess = async (response) => {
13
13
  const { tokenId, profileObj, googleId } = response;
@@ -36,10 +36,8 @@ export const useGoogleAuth = () => {
36
36
  type: "error",
37
37
  });
38
38
  case "SUCCESS":
39
- onLogin({
40
- token: result.data.token,
41
- member: result.data.member
42
- });
39
+ onTokenChange(result.data.token);
40
+ onLogin({ token: result.data.token, member: result.data.member });
43
41
  break;
44
42
  }
45
43
  };
@@ -21,6 +21,6 @@ declare const useCreatePassword: () => {
21
21
  handleSkip: ({ onResult }: {
22
22
  onResult: () => void;
23
23
  }) => void;
24
- disabled: boolean;
24
+ isContinueDisabled: boolean;
25
25
  };
26
26
  export { useCreatePassword };
@@ -24,5 +24,6 @@ declare const useResetPassword: ({ sessionToken }: {
24
24
  onResult: () => void;
25
25
  }) => void;
26
26
  handleConfirmPassword: (text: string) => void;
27
+ isContinueDisabled: boolean;
27
28
  };
28
29
  export { useResetPassword };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "description": "Truworth Auth Package for React Native and Web",
7
- "version": "1.2.9",
7
+ "version": "1.2.11",
8
8
  "main": "build/src/index.js",
9
9
  "types": "build/types/index.d.ts",
10
10
  "files": [
@@ -46,7 +46,7 @@
46
46
  "lottie-react": "^2.4.1",
47
47
  "lottie-react-native": "6.7.2",
48
48
  "moment": "^2.30.1",
49
- "next": "^15.0.4",
49
+ "next": "15.5.9",
50
50
  "react": "18.3.1",
51
51
  "react-dom": "^18.2.0",
52
52
  "react-google-login": "^5.2.2",
@@ -63,7 +63,6 @@
63
63
  "react-native-rsa-native": "2.0.5",
64
64
  "react-native-safe-area-context": "4.14.0",
65
65
  "react-native-svg": "15.8.0",
66
- "react-native-svg-uri": "^1.2.3",
67
66
  "react-native-vector-icons": "9.2.0",
68
67
  "react-redux": "^9.2.0",
69
68
  "sweetalert2": "^11.23.0",