@truworth/twc-auth 1.2.7 → 1.2.9

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.
@@ -10,6 +10,11 @@ const { gray } = Colors;
10
10
  const VerifyMobileOTP = ({ validateOTP, timer, status, resendOTP, phone }) => {
11
11
  const [otp, setOtp] = useState('');
12
12
  const { otpValue } = useAuthPackageContext();
13
+ useEffect(() => {
14
+ if (otp && otp.length == 6) {
15
+ return validateOTP(otp);
16
+ }
17
+ }, [otp]);
13
18
  useEffect(() => {
14
19
  if (otpValue && otpValue.length == 6) {
15
20
  setOtp(otpValue);
@@ -24,7 +29,7 @@ const VerifyMobileOTP = ({ validateOTP, timer, status, resendOTP, phone }) => {
24
29
  }, codeInputHighlightStyle: { borderColor: '#03DAC6' }, style: {
25
30
  height: 50,
26
31
  width: Dimensions.get('window').width - 100,
27
- }, code: otp ?? '', onCodeFilled: code => validateOTP(code) }) }), timer <= 0 &&
32
+ }, code: otp ?? '', onCodeFilled: code => setOtp(code) }) }), timer <= 0 &&
28
33
  _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center' }, children: [_jsx(Text, { style: { fontSize: 12, color: '#000', fontWeight: '400', opacity: 0.5 }, children: "Did not receive OTP?" }), _jsx(TouchableOpacity, { disabled: timer > 0, onPress: () => {
29
34
  setOtp('');
30
35
  resendOTP();
@@ -149,7 +149,6 @@ const AuthProvider = ({ children, LogoComponent, session, appConfig, onLogin, on
149
149
  }, []);
150
150
  const handleOtpReceived = (otp) => {
151
151
  setOtpValue(otp);
152
- setTimeout(() => setOtpValue(''), 0);
153
152
  };
154
153
  const AuthContextValues = {
155
154
  token,
@@ -1,18 +1,14 @@
1
- import { useEffect, useMemo, useState } from 'react';
1
+ import { useCallback, useEffect, useMemo, useState } from 'react';
2
2
  import { showMessage } from '../helpers/show-message';
3
3
  import { useAuthPackageContext } from './internal/useAuthPackageContext';
4
4
  import { createHttpClient } from '../helpers/network';
5
5
  const useRequest = () => {
6
- const { token: sessionToken, logout, refreshSession } = useAuthPackageContext();
7
- const [token, setToken] = useState(sessionToken);
8
- useEffect(() => {
9
- setToken(sessionToken);
10
- }, [sessionToken]);
6
+ const { token, logout, refreshSession } = useAuthPackageContext();
11
7
  const { request } = useMemo(() => createHttpClient({
12
8
  token,
13
9
  onRefreshSession: async (token) => refreshSession?.({ token }),
14
10
  onLogout: async () => logout(),
15
- }), [token, logout, refreshSession]);
11
+ }), [token]);
16
12
  const makeRequest = async ({ url, method, body, onSuccess, onFailure, ...axiosOptions }) => {
17
13
  if (!token) {
18
14
  return;
@@ -35,7 +35,11 @@ const EnterEmail = ({ onContinue, onPressSignInWithSSO }) => {
35
35
  });
36
36
  },
37
37
  disabled: !isEmailValid,
38
- }, children: [_jsx(Form, { className: "w-full", form: form, children: _jsx(Form.Item, { name: "email", label: "Email", children: _jsx(TextInput, { type: "email", value: email, size: "medium", placeholder: "example@domain", ...form.register('email', {
38
+ }, children: [_jsx(Form, { className: "w-full", form: form, onSubmit: () => {
39
+ handleEmailExists({
40
+ onValidate: ({ emailExist }) => onContinue({ email, emailExist })
41
+ });
42
+ }, children: _jsx(Form.Item, { name: "email", label: "Email", children: _jsx(TextInput, { type: "email", value: email, size: "medium", placeholder: "example@domain", ...form.register('email', {
39
43
  onChange: (e) => {
40
44
  handleEmailChange(e.target.value);
41
45
  }
@@ -9,12 +9,14 @@ import { showMessage } from "../../../../helpers/show-message";
9
9
  const useEnterPassword = () => {
10
10
  const [password, setPassword] = useState("");
11
11
  const [isPasswordVisible, setIsPasswordVisible] = useState(false);
12
+ const [invalidPassword, setInvalidPassword] = useState(false);
12
13
  const [loading, setLoading] = useState(false);
13
14
  const { onTokenChange, onLogin, appConfig } = useAuthPackageContext();
14
15
  const togglePasswordVisibility = useCallback(() => {
15
16
  setIsPasswordVisible((prev) => !prev);
16
17
  }, []);
17
18
  const handlePasswordChange = useCallback((value) => {
19
+ setInvalidPassword(false);
18
20
  setPassword(value);
19
21
  }, []);
20
22
  const handleSubmit = useCallback(async ({ email, source, verifyEmailOTP }) => {
@@ -46,6 +48,7 @@ const useEnterPassword = () => {
46
48
  catch (error) {
47
49
  const errorMessage = error?.response?.data?.errors?.[0]?.message;
48
50
  if (error?.response?.status === 400) {
51
+ setInvalidPassword(true);
49
52
  showMessage({ message: errorMessage ?? 'Email and password do not match!' });
50
53
  return;
51
54
  }
@@ -67,7 +70,8 @@ const useEnterPassword = () => {
67
70
  handleSubmit,
68
71
  isDisabled,
69
72
  handlePasswordChange,
70
- appName: appConfig.appName
73
+ appName: appConfig.appName,
74
+ invalidPassword
71
75
  };
72
76
  };
73
77
  export { useEnterPassword };
@@ -29,7 +29,18 @@ const EnterPassword = ({ email, onPressBack, onVerifiedResetPasswordOTP }) => {
29
29
  });
30
30
  },
31
31
  disabled: !password || !email || loading,
32
- }, onPressBack: onPressBack, children: [_jsx(Form, { className: "w-full", form: form, children: _jsx(Form.Item, { name: "password", label: "Password", children: _jsx(PasswordInput, { placeholder: "Enter your password", value: password, showStrengthIndicator: false, className: `border rounded-md px-3 py-2 border-gray-300`, ...form.register('password', {
32
+ }, onPressBack: onPressBack, children: [_jsx(Form, { className: "w-full", form: form, onSubmit: () => {
33
+ if (email)
34
+ handleSubmit({
35
+ email,
36
+ source: 'web',
37
+ verifyEmailOTP: ({ mfaEnabled, sessionToken }) => {
38
+ setMfaSessionToken(sessionToken);
39
+ setMfaEnabled(mfaEnabled);
40
+ setShowLoginWithEmailOTPModal(true);
41
+ }
42
+ });
43
+ }, children: _jsx(Form.Item, { name: "password", label: "Password", children: _jsx(PasswordInput, { placeholder: "Enter your password", value: password, showStrengthIndicator: false, className: `border rounded-md px-3 py-2 border-gray-300`, ...form.register('password', {
33
44
  onChange: (e) => {
34
45
  handlePasswordChange(e.target.value);
35
46
  }
@@ -7,7 +7,7 @@ import { useEnterPassword } from './hooks/internal/useEnterPassword';
7
7
  const { primary } = Colors;
8
8
  const EnterPassword = ({ navigation, route }) => {
9
9
  const { email } = route.params;
10
- const { loading, password, isPasswordVisible, togglePasswordVisibility, handlePasswordChange, isDisabled, handleSubmit } = useEnterPassword();
10
+ const { loading, password, isPasswordVisible, togglePasswordVisibility, handlePasswordChange, isDisabled, handleSubmit, invalidPassword } = useEnterPassword();
11
11
  return (_jsxs(Layout, { style: { flex: 1, backgroundColor: primary.white }, children: [_jsxs(ScreenLayout, { title: "Enter Your Password", buttonProps: {
12
12
  loading,
13
13
  label: 'Continue',
@@ -22,7 +22,10 @@ const EnterPassword = ({ navigation, route }) => {
22
22
  });
23
23
  },
24
24
  disabled: isDisabled,
25
- }, children: [_jsx(View, { style: { position: 'relative' }, children: _jsx(TextInputField, { placeholder: 'Enter password...', onChangeValue: handlePasswordChange, secureTextEntry: !isPasswordVisible, value: password, rightIcon2: isPasswordVisible ? 'eye-outline' : 'eye-off-outline', onPressRightIcon2: () => togglePasswordVisibility(), autoFocus: true }) }), _jsx(TouchableOpacity, { activeOpacity: 0.8, style: { marginTop: 10, alignSelf: 'flex-end' }, onPress: () => navigation.navigate('VerifyResetPasswordOTP', { email }), children: _jsx(Text, { style: {
25
+ }, children: [_jsx(View, { style: { position: 'relative' }, children: _jsx(TextInputField, { placeholder: 'Enter password...', onChangeValue: handlePasswordChange, secureTextEntry: !isPasswordVisible, value: password, rightIcon2: isPasswordVisible ? 'eye-outline' : 'eye-off-outline', onPressRightIcon2: () => togglePasswordVisibility(), error: {
26
+ show: invalidPassword,
27
+ message: 'Email and password do not match!'
28
+ }, autoFocus: true }) }), _jsx(TouchableOpacity, { activeOpacity: 0.8, style: { marginTop: 10, alignSelf: 'flex-end' }, onPress: () => navigation.navigate('VerifyResetPasswordOTP', { email }), children: _jsx(Text, { style: {
26
29
  fontSize: 12, fontWeight: '600',
27
30
  color: primary.primary_main, lineHeight: 20,
28
31
  }, children: "Forgot Password?" }) })] }), _jsxs(View, { style: { paddingHorizontal: 16 }, children: [_jsxs(View, { style: {
@@ -20,5 +20,6 @@ declare const useEnterPassword: () => {
20
20
  isDisabled: boolean;
21
21
  handlePasswordChange: (value: string) => void;
22
22
  appName: string | undefined;
23
+ invalidPassword: boolean;
23
24
  };
24
25
  export { useEnterPassword };
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.7",
7
+ "version": "1.2.9",
8
8
  "main": "build/src/index.js",
9
9
  "types": "build/types/index.d.ts",
10
10
  "files": [
@@ -26,7 +26,7 @@
26
26
  "@react-native-google-signin/google-signin": "12.2.1",
27
27
  "@react-navigation/native": "6.1.17",
28
28
  "@react-navigation/native-stack": "6.10.0",
29
- "@truworth/twc-rn-common": "1.0.15",
29
+ "@truworth/twc-rn-common": "1.1.2",
30
30
  "@truworth/twc-web-design": "1.11.0",
31
31
  "@twotalltotems/react-native-otp-input": "1.3.11",
32
32
  "@types/crypto-js": "^4.2.2",