@truworth/twc-auth 1.2.3 → 1.2.4
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/build/assets/loading-spinner.json +1 -0
- package/build/src/api/auth.js +36 -0
- package/build/src/components/ScreenLayout/index.native.js +2 -2
- package/build/src/components/VerifyEmailOTP/index.native.js +14 -11
- package/build/src/contexts/AuthContext.js +1 -1
- package/build/src/enums/index.js +2 -0
- package/build/src/enums/loginMethod.enum.js +8 -0
- package/build/src/enums/registrationMethod.enum.js +7 -0
- package/build/src/index.js +3 -2
- package/build/src/navigator/index.native.js +5 -1
- package/build/src/screens/EnterEmail/hooks/internal/useEnterEmail.js +22 -40
- package/build/src/screens/EnterEmail/index.js +7 -9
- package/build/src/screens/EnterEmail/index.native.js +11 -11
- package/build/src/screens/EnterPassword/index.js +12 -3
- package/build/src/screens/Login/components/LoginWebComponent/index.js +16 -15
- package/build/src/screens/SSOLogin/AuthWebView/index.js +9 -0
- package/build/src/screens/SSOLogin/AuthWebView/index.native.js +27 -0
- package/build/src/screens/SSOLogin/AuthWebView/types.js +1 -0
- package/build/src/screens/SSOLogin/AuthenticationMethods/hooks/internal/useSSOAuthenticationMethods.js +38 -0
- package/build/src/screens/SSOLogin/AuthenticationMethods/index.js +48 -0
- package/build/src/screens/SSOLogin/AuthenticationMethods/index.native.js +58 -0
- package/build/src/screens/SSOLogin/AuthenticationMethods/types.js +1 -0
- package/build/src/screens/SSOLogin/SSOCallback/components/SSOCallbackComponent/index.js +59 -0
- package/build/src/screens/SSOLogin/SSOCallback/components/SSOCallbackComponent/index.native.js +6 -0
- package/build/src/screens/SSOLogin/SSOCallback/hooks/internal/useSSOCallback.js +42 -0
- package/build/src/screens/SSOLogin/SSOCallback/index.js +9 -0
- package/build/src/screens/SSOLogin/SSOCallback/index.native.js +35 -0
- package/build/src/screens/SSOLogin/SSOCallback/types.js +1 -0
- package/build/src/screens/SSOLogin/SearchOrganization/hooks/internal/useSSOSearchOrganization.js +71 -0
- package/build/src/screens/SSOLogin/SearchOrganization/index.js +46 -0
- package/build/src/screens/SSOLogin/SearchOrganization/index.native.js +37 -0
- package/build/src/screens/SSOLogin/SearchOrganization/types.js +1 -0
- package/build/src/screens/SignUp/components/SignUpForm/index.js +91 -65
- package/build/src/screens/SignUp/components/SignUpWebComponent/index.js +22 -53
- package/build/src/screens/SignUp/hooks/internal/useSignUp.js +77 -81
- package/build/src/screens/SignUp/index.native.js +76 -77
- package/build/src/screens/UserConsent/hooks/internal/useConsent.js +10 -3
- package/build/src/screens/UserConsent/index.js +38 -18
- package/build/src/screens/UserConsent/index.native.js +1 -1
- package/build/src/screens/VerifyMobile/hooks/internal/useVerifyMobile.js +2 -2
- package/build/src/screens/Welcome/index.js +2 -3
- package/build/src/screens/Welcome/index.native.js +1 -1
- package/build/src/types/types.js +1 -1
- package/build/types/api/auth.d.ts +11 -0
- package/build/types/components/ScreenLayout/index.native.d.ts +1 -1
- package/build/types/components/ScreenLayout/types.d.ts +1 -0
- package/build/types/enums/index.d.ts +2 -0
- package/build/types/enums/loginMethod.enum.d.ts +7 -0
- package/build/types/enums/registrationMethod.enum.d.ts +6 -0
- package/build/types/index.d.ts +3 -2
- package/build/types/navigator/index.native.d.ts +14 -1
- package/build/types/screens/EnterEmail/hooks/internal/useEnterEmail.d.ts +3 -4
- package/build/types/screens/EnterEmail/index.d.ts +2 -6
- package/build/types/screens/EnterEmail/types.d.ts +8 -0
- package/build/types/screens/EnterPassword/index.d.ts +1 -1
- package/build/types/screens/EnterPassword/types.d.ts +6 -2
- package/build/types/screens/SSOLogin/AuthWebView/index.d.ts +2 -0
- package/build/types/screens/SSOLogin/AuthWebView/index.native.d.ts +4 -0
- package/build/types/screens/SSOLogin/AuthWebView/types.d.ts +8 -0
- package/build/types/screens/SSOLogin/AuthenticationMethods/hooks/internal/useSSOAuthenticationMethods.d.ts +9 -0
- package/build/types/screens/SSOLogin/AuthenticationMethods/index.d.ts +3 -0
- package/build/types/screens/SSOLogin/AuthenticationMethods/index.native.d.ts +4 -0
- package/build/types/screens/SSOLogin/AuthenticationMethods/types.d.ts +11 -0
- package/build/types/screens/SSOLogin/SSOCallback/components/SSOCallbackComponent/index.d.ts +2 -0
- package/build/types/screens/SSOLogin/SSOCallback/components/SSOCallbackComponent/index.native.d.ts +2 -0
- package/build/types/screens/SSOLogin/SSOCallback/hooks/internal/useSSOCallback.d.ts +11 -0
- package/build/types/screens/SSOLogin/SSOCallback/index.d.ts +2 -0
- package/build/types/screens/SSOLogin/SSOCallback/index.native.d.ts +4 -0
- package/build/types/screens/SSOLogin/SSOCallback/types.d.ts +11 -0
- package/build/types/screens/SSOLogin/SearchOrganization/hooks/internal/useSSOSearchOrganization.d.ts +18 -0
- package/build/types/screens/SSOLogin/SearchOrganization/index.d.ts +3 -0
- package/build/types/screens/SSOLogin/SearchOrganization/index.native.d.ts +4 -0
- package/build/types/screens/SSOLogin/SearchOrganization/types.d.ts +13 -0
- package/build/types/screens/SignUp/components/SignUpForm/index.d.ts +1 -1
- package/build/types/screens/SignUp/components/SignUpForm/type.d.ts +1 -4
- package/build/types/screens/SignUp/components/SignUpWebComponent/types.d.ts +1 -16
- package/build/types/screens/SignUp/hooks/internal/useSignUp.d.ts +16 -18
- package/build/types/screens/SignUp/types.d.ts +29 -7
- package/build/types/screens/UserConsent/hooks/internal/useConsent.d.ts +1 -1
- package/build/types/screens/UserConsent/index.d.ts +1 -1
- package/build/types/screens/UserConsent/types.d.ts +19 -13
- package/build/types/types/types.d.ts +16 -2
- package/package.json +6 -4
- package/build/types/screens/Login/components/LoginWebComponent/types.d.ts +0 -6
- /package/build/src/screens/{Login/components/LoginWebComponent → EnterEmail}/types.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"v":"5.8.1","fr":30,"ip":0,"op":60,"w":300,"h":300,"nm":"loading_6","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 2","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":60,"s":[360]}],"ix":10},"p":{"a":0,"k":[150.00000000000003,150.00000000000003,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[30.000000000000004,30.000000000000004,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[300,300],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[0.12941176470588237,0.7411764705882353,0.7764705882352941,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":50,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"tm","s":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":10,"s":[0]},{"t":60,"s":[99]}],"ix":1},"e":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":0,"s":[1]},{"t":50,"s":[100]}],"ix":2},"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":60,"s":[3]}],"ix":3},"m":1,"ix":2,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false}],"ip":0,"op":300,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":30,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[150.00000000000003,150.00000000000003,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[30.000000000000004,30.000000000000004,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[300,300],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[0.7450980392156863,0.9254901960784314,0.9372549019607843,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":50,"ix":5},"lc":1,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":300,"st":0,"bm":0}],"markers":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { axiosClient } from "./axiosClient";
|
|
2
|
+
/** Check if mobile exists */
|
|
3
|
+
const checkMobileExists = async (phone) => {
|
|
4
|
+
try {
|
|
5
|
+
const { data } = await axiosClient({
|
|
6
|
+
url: '/auth/mobile-exists',
|
|
7
|
+
method: 'POST',
|
|
8
|
+
data: { phone },
|
|
9
|
+
});
|
|
10
|
+
return { mobileExist: data?.exists, linkedAccounts: data?.memberDetails };
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
if (err?.response?.status == 404) {
|
|
14
|
+
return { mobileExist: false };
|
|
15
|
+
}
|
|
16
|
+
throw err;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/** Check if email exists */
|
|
20
|
+
const checkEmailExists = async (email) => {
|
|
21
|
+
try {
|
|
22
|
+
const { data } = await axiosClient({
|
|
23
|
+
url: '/auth/email-exists',
|
|
24
|
+
method: 'POST',
|
|
25
|
+
data: { email },
|
|
26
|
+
});
|
|
27
|
+
return { emailExist: data?.exists, loginType: data?.loginType };
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (err?.response?.status === 404) {
|
|
31
|
+
return { emailExist: false };
|
|
32
|
+
}
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export { checkMobileExists, checkEmailExists };
|
|
@@ -2,9 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { View, Text } from 'react-native';
|
|
3
3
|
import { Colors, Header, RoundedButton } from '@truworth/twc-rn-common';
|
|
4
4
|
const { gray } = Colors;
|
|
5
|
-
const ScreenLayout = ({ children, title, subTitle, hideHeader, buttonProps, containerStyle, accessoryRight }) => {
|
|
5
|
+
const ScreenLayout = ({ children, headerTitle, title, subTitle, hideHeader, buttonProps, containerStyle, accessoryRight }) => {
|
|
6
6
|
return (_jsxs(_Fragment, { children: [!hideHeader &&
|
|
7
|
-
_jsx(Header, { accessoryRight: accessoryRight }), _jsxs(View, { style: [{ paddingVertical: 32, paddingHorizontal: 16 }, containerStyle], children: [Boolean(title) &&
|
|
7
|
+
_jsx(Header, { title: headerTitle, accessoryRight: accessoryRight }), _jsxs(View, { style: [{ paddingVertical: 32, paddingHorizontal: 16 }, containerStyle], children: [Boolean(title) &&
|
|
8
8
|
_jsx(Text, { textBreakStrategy: 'simple', style: {
|
|
9
9
|
fontSize: 20, fontWeight: '600', color: gray.gray_900,
|
|
10
10
|
lineHeight: 32, marginBottom: 32,
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Dimensions, Platform, ScrollView, Text, TouchableOpacity, View } from "react-native";
|
|
3
3
|
import { Layout } from "@ui-kitten/components";
|
|
4
4
|
import { Header, Colors, CustomKeyboardAvoidingView } from "@truworth/twc-rn-common";
|
|
5
|
-
import { ScreenLayout } from "../ScreenLayout";
|
|
6
5
|
import { OTPStatusLabel } from "../OTPStatusLabel/index.native";
|
|
7
6
|
import OTPInputView from "@twotalltotems/react-native-otp-input";
|
|
7
|
+
const { gray } = Colors;
|
|
8
8
|
const VerifyEmailOTP = ({ email, status, validateOTP, resendOTP, resendOTPCounter }) => {
|
|
9
|
-
return (_jsxs(Layout, { style: { flex: 1, backgroundColor: '#
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
return (_jsxs(Layout, { style: { flex: 1, backgroundColor: '#FFFFFF' }, children: [_jsx(Header, {}), _jsxs(CustomKeyboardAvoidingView, { behavior: Platform.OS === 'ios' ? 'padding' : undefined, keyboardVerticalOffset: 0, children: [_jsxs(ScrollView, { style: { paddingHorizontal: 20, paddingTop: 32, flex: 1 }, showsVerticalScrollIndicator: false, children: [_jsxs(Text, { textBreakStrategy: 'simple', style: {
|
|
10
|
+
fontSize: 20, fontWeight: '600', color: gray.gray_900,
|
|
11
|
+
lineHeight: 32, marginBottom: 32,
|
|
12
|
+
}, children: ["OTP sent to ", '\n', email] }), _jsx(View, { style: { justifyContent: 'center', flexDirection: 'row', marginBottom: 30, position: 'relative' }, children: _jsx(OTPInputView, { pinCount: 6, autoFocusOnLoad: false, codeInputFieldStyle: {
|
|
13
|
+
fontSize: 20, color: 'black',
|
|
14
|
+
height: 45, width: 30,
|
|
15
|
+
borderWidth: 0, borderBottomWidth: 1,
|
|
16
|
+
}, codeInputHighlightStyle: { borderColor: '#03DAC6' }, style: {
|
|
17
|
+
height: 50,
|
|
18
|
+
width: Dimensions.get('window').width - 100,
|
|
19
|
+
}, onCodeFilled: code => validateOTP(code) }) }), resendOTPCounter < 3 &&
|
|
20
|
+
_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center' }, children: [_jsxs(Text, { style: { fontSize: 14, fontWeight: '500', color: gray.gray_400, lineHeight: 20 }, children: ["Did not receive OTP?", ' '] }), _jsx(TouchableOpacity, { activeOpacity: 0.8, onPress: resendOTP, children: _jsx(Text, { style: { fontSize: 14, fontWeight: '500', color: '#2cbaa4', lineHeight: 20 }, children: "Re-send OTP" }) })] })] }), _jsx(View, { style: { alignSelf: 'flex-end', width: '100%' }, children: _jsx(OTPStatusLabel, { status: status }) })] })] }));
|
|
18
21
|
};
|
|
19
22
|
export { VerifyEmailOTP };
|
|
@@ -119,8 +119,8 @@ const AuthProvider = ({ children, LogoComponent, session, appConfig, onLogin, on
|
|
|
119
119
|
const clearSession = useCallback(() => {
|
|
120
120
|
setToken('');
|
|
121
121
|
setClient(null);
|
|
122
|
-
setProfile(null);
|
|
123
122
|
setRegistrationMethod(null);
|
|
123
|
+
setProfile(null);
|
|
124
124
|
}, []);
|
|
125
125
|
/**
|
|
126
126
|
* Helper to normalize and format user profile data
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export var LoginMethodCode;
|
|
2
|
+
(function (LoginMethodCode) {
|
|
3
|
+
LoginMethodCode[LoginMethodCode["EmailPassword"] = 1] = "EmailPassword";
|
|
4
|
+
LoginMethodCode[LoginMethodCode["Facebook"] = 2] = "Facebook";
|
|
5
|
+
LoginMethodCode[LoginMethodCode["Google"] = 3] = "Google";
|
|
6
|
+
LoginMethodCode[LoginMethodCode["Apple"] = 4] = "Apple";
|
|
7
|
+
LoginMethodCode[LoginMethodCode["SSO"] = 5] = "SSO";
|
|
8
|
+
})(LoginMethodCode || (LoginMethodCode = {}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export var RegistrationMethod;
|
|
2
|
+
(function (RegistrationMethod) {
|
|
3
|
+
RegistrationMethod["EMAIL"] = "email";
|
|
4
|
+
RegistrationMethod["SSO"] = "sso";
|
|
5
|
+
RegistrationMethod["MOBILE"] = "mobile";
|
|
6
|
+
RegistrationMethod["SOCIAL"] = "social";
|
|
7
|
+
})(RegistrationMethod || (RegistrationMethod = {}));
|
package/build/src/index.js
CHANGED
|
@@ -10,5 +10,6 @@ export * from './api/axiosClient';
|
|
|
10
10
|
// export navigator/router
|
|
11
11
|
export * from './navigator';
|
|
12
12
|
// export components
|
|
13
|
-
export * from './screens/Login/components/LoginWebComponent';
|
|
14
|
-
export * from './screens/SignUp/components/SignUpWebComponent';
|
|
13
|
+
export * from './screens/Login/components/LoginWebComponent/index';
|
|
14
|
+
export * from './screens/SignUp/components/SignUpWebComponent/index';
|
|
15
|
+
export * from './screens/SSOLogin/SSOCallback/components/SSOCallbackComponent/index';
|
|
@@ -12,8 +12,12 @@ import VerifyEmail from '../screens/VerifyEmail/index.native';
|
|
|
12
12
|
import LoginWithEmailOTP from '../screens/LoginWithEmailOTP/index.native';
|
|
13
13
|
import VerifyResetPasswordOTP from '../screens/VerifyResetPasswordOTP/index.native';
|
|
14
14
|
import ResetPassword from '../screens/ResetPassword/index.native';
|
|
15
|
+
import SSOSearchOrganization from '../screens/SSOLogin/SearchOrganization/index.native';
|
|
16
|
+
import SSOAuthenticationMethods from '../screens/SSOLogin/AuthenticationMethods/index.native';
|
|
17
|
+
import SSOAuthWebView from '../screens/SSOLogin/AuthWebView/index.native';
|
|
18
|
+
import SSOCallback from '../screens/SSOLogin/SSOCallback/index.native';
|
|
15
19
|
const { Navigator, Screen } = createNativeStackNavigator();
|
|
16
20
|
const AuthNavigator = () => {
|
|
17
|
-
return (_jsxs(Navigator, { screenOptions: { headerShown: false }, children: [_jsx(Screen, { name: "Welcome", component: Welcome }), _jsx(Screen, { name: "EnterEmail", component: EnterEmail }), _jsx(Screen, { name: "EnterPassword", component: EnterPassword }), _jsx(Screen, { name: "SignUp", component: SignUp }), _jsx(Screen, { name: "CountryCode", component: CountryCode }), _jsx(Screen, { name: "CreatePassword", component: CreatePassword }), _jsx(Screen, { name: "UserConsent", component: UserConsent }), _jsx(Screen, { name: "VerifyMobile", component: VerifyMobile }), _jsx(Screen, { name: "VerifyEmail", component: VerifyEmail }), _jsx(Screen, { name: "LoginWithEmailOTP", component: LoginWithEmailOTP }), _jsx(Screen, { name: "VerifyResetPasswordOTP", component: VerifyResetPasswordOTP }), _jsx(Screen, { name: "ResetPassword", component: ResetPassword })] }));
|
|
21
|
+
return (_jsxs(Navigator, { screenOptions: { headerShown: false }, children: [_jsx(Screen, { name: "Welcome", component: Welcome }), _jsx(Screen, { name: "EnterEmail", component: EnterEmail }), _jsx(Screen, { name: "EnterPassword", component: EnterPassword }), _jsx(Screen, { name: "SignUp", component: SignUp }), _jsx(Screen, { name: "CountryCode", component: CountryCode }), _jsx(Screen, { name: "CreatePassword", component: CreatePassword }), _jsx(Screen, { name: "UserConsent", component: UserConsent }), _jsx(Screen, { name: "VerifyMobile", component: VerifyMobile }), _jsx(Screen, { name: "VerifyEmail", component: VerifyEmail }), _jsx(Screen, { name: "LoginWithEmailOTP", component: LoginWithEmailOTP }), _jsx(Screen, { name: "VerifyResetPasswordOTP", component: VerifyResetPasswordOTP }), _jsx(Screen, { name: "ResetPassword", component: ResetPassword }), _jsx(Screen, { name: "SSOSearchOrganization", component: SSOSearchOrganization }), _jsx(Screen, { name: "SSOAuthenticationMethods", component: SSOAuthenticationMethods }), _jsx(Screen, { name: "SSOAuthWebView", component: SSOAuthWebView }), _jsx(Screen, { name: "SSOCallback", component: SSOCallback })] }));
|
|
18
22
|
};
|
|
19
23
|
export { AuthNavigator };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useCallback, useState } from "react";
|
|
2
2
|
import { showMessage } from "../../../../helpers/show-message";
|
|
3
3
|
import { useAuthPackageContext } from "../../../../hooks/internal/useAuthPackageContext";
|
|
4
|
-
import {
|
|
4
|
+
import { checkEmailExists } from "../../../../api/auth";
|
|
5
|
+
import { LoginMethodCode } from "../../../../enums";
|
|
5
6
|
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
6
7
|
/**
|
|
7
8
|
* @internal
|
|
@@ -19,50 +20,31 @@ const useEnterEmail = () => {
|
|
|
19
20
|
setInvalidEmail(!emailRegex.test(value));
|
|
20
21
|
setEmail(value);
|
|
21
22
|
}, [emailRegex]);
|
|
22
|
-
const handleValidateEmail = ({
|
|
23
|
-
if (loading || isInvalidEmail || !email)
|
|
24
|
-
return;
|
|
23
|
+
const handleValidateEmail = async ({ onContinue }) => {
|
|
25
24
|
setLoading(true);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
if (code !== 1) {
|
|
39
|
-
let providerName = 'your social account';
|
|
40
|
-
switch (code) {
|
|
41
|
-
case 2:
|
|
42
|
-
providerName = 'Facebook';
|
|
43
|
-
break;
|
|
44
|
-
case 3:
|
|
45
|
-
providerName = 'Google';
|
|
46
|
-
break;
|
|
47
|
-
case 4:
|
|
48
|
-
providerName = 'Apple';
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
setLoginType(providerName);
|
|
25
|
+
try {
|
|
26
|
+
const { emailExist, loginType } = await checkEmailExists(email);
|
|
27
|
+
const code = Number(loginType);
|
|
28
|
+
if (emailExist && code !== LoginMethodCode.EmailPassword) {
|
|
29
|
+
const loginTypesMap = {
|
|
30
|
+
[LoginMethodCode.Facebook]: 'Facebook',
|
|
31
|
+
[LoginMethodCode.Google]: 'Google',
|
|
32
|
+
[LoginMethodCode.Apple]: 'Apple',
|
|
33
|
+
[LoginMethodCode.SSO]: 'SSO',
|
|
34
|
+
};
|
|
35
|
+
setLoginType(loginTypesMap[code] || 'your social account');
|
|
52
36
|
setLoginConflictModalVisible(true);
|
|
53
37
|
return;
|
|
54
38
|
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
39
|
+
onContinue({ emailExist });
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
const errorMessage = err?.response?.data?.errors?.[0]?.message ?? 'Something went wrong';
|
|
43
|
+
showMessage({ message: errorMessage });
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
58
46
|
setLoading(false);
|
|
59
|
-
|
|
60
|
-
onResult({ email, emailExist: false });
|
|
61
|
-
}
|
|
62
|
-
if (err?.response?.status >= 500) {
|
|
63
|
-
showMessage({ message: 'Something went wrong' });
|
|
64
|
-
}
|
|
65
|
-
});
|
|
47
|
+
}
|
|
66
48
|
};
|
|
67
49
|
const clearText = useCallback(() => {
|
|
68
50
|
setEmail('');
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Form, TextInput, useForm } from '@truworth/twc-web-design';
|
|
2
|
+
import { Button, Form, TextInput, useForm } from '@truworth/twc-web-design';
|
|
3
3
|
import { ConfirmationModal as LoginConflictModal } from '../../components/ConfirmationModal';
|
|
4
4
|
import { ScreenLayout } from "../../components/ScreenLayout";
|
|
5
5
|
import { useEnterEmail } from "./hooks/internal/useEnterEmail";
|
|
6
6
|
import { SupportDetails } from '../../components/SupportDetails';
|
|
7
|
-
const EnterEmail = ({
|
|
7
|
+
const EnterEmail = ({ onContinue, onPressSignInWithSSO }) => {
|
|
8
8
|
const { loading, email, isInvalidEmail, loginConflictModalVisible, loginConflictErrorTitle, loginConflictErrorDescription, enterEmail, appName, handleValidateEmail, setLoginConflictModalVisible, } = useEnterEmail();
|
|
9
9
|
const form = useForm({ defaultValues: { email } });
|
|
10
10
|
return (_jsxs(_Fragment, { children: [_jsxs(ScreenLayout, { title: `Hi, Welcome To ${appName}!`, subTitle: "Please enter email to get started.", buttonProps: {
|
|
@@ -12,19 +12,17 @@ const EnterEmail = ({ onResult }) => {
|
|
|
12
12
|
label: 'Continue',
|
|
13
13
|
onClick: () => {
|
|
14
14
|
if (!loading && !isInvalidEmail) {
|
|
15
|
-
handleValidateEmail({
|
|
15
|
+
handleValidateEmail({
|
|
16
|
+
onContinue: (params) => onContinue({ email, emailExist: params.emailExist })
|
|
17
|
+
});
|
|
16
18
|
}
|
|
17
19
|
},
|
|
18
20
|
disabled: isInvalidEmail || loading,
|
|
19
|
-
}, children: [_jsx(Form, { className: "w-full", form: form,
|
|
20
|
-
if (!loading && !isInvalidEmail) {
|
|
21
|
-
handleValidateEmail({ onResult });
|
|
22
|
-
}
|
|
23
|
-
}, children: _jsx(Form.Item, { name: "email", label: "Email", children: _jsx(TextInput, { type: "email", value: email, size: "medium", placeholder: "example@domain", ...form.register('email', {
|
|
21
|
+
}, 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', {
|
|
24
22
|
onChange: (e) => {
|
|
25
23
|
enterEmail(e.target.value);
|
|
26
24
|
}
|
|
27
25
|
}) }) }) }), loginConflictModalVisible &&
|
|
28
|
-
_jsx(LoginConflictModal, { title: loginConflictErrorTitle, primaryLabel: 'Okay', description: loginConflictErrorDescription, visible: loginConflictModalVisible, onProceed: () => setLoginConflictModalVisible(false), onClose: () => setLoginConflictModalVisible(false) })] }), _jsx(SupportDetails, {})] }));
|
|
26
|
+
_jsx(LoginConflictModal, { title: loginConflictErrorTitle, primaryLabel: 'Okay', description: loginConflictErrorDescription, visible: loginConflictModalVisible, onProceed: () => setLoginConflictModalVisible(false), onClose: () => setLoginConflictModalVisible(false) })] }), _jsx(Button, { isFullWidth: true, type: "button", label: 'Sign In with SSO', variant: 'secondary', className: 'flex-none mt-6', onClick: onPressSignInWithSSO }), _jsx(SupportDetails, {})] }));
|
|
29
27
|
};
|
|
30
28
|
export default EnterEmail;
|
|
@@ -5,26 +5,26 @@ import { Colors, TextInputField } from '@truworth/twc-rn-common';
|
|
|
5
5
|
import { useEnterEmail } from './hooks/internal/useEnterEmail';
|
|
6
6
|
import { ScreenLayout } from '../../components/ScreenLayout/index.native';
|
|
7
7
|
import { ConfirmationModal as LoginConflictModal } from '../../components/ConfirmationModal';
|
|
8
|
+
import { RegistrationMethod } from '../../enums';
|
|
8
9
|
const { utility } = Colors;
|
|
9
10
|
const EnterEmail = ({ navigation }) => {
|
|
10
11
|
const { loading, email, isInvalidEmail, loginConflictModalVisible, loginConflictErrorTitle, loginConflictErrorDescription, enterEmail, clearText, handleValidateEmail, onRegistrationMethodChange, setLoginConflictModalVisible, } = useEnterEmail();
|
|
12
|
+
const onContinue = (params) => {
|
|
13
|
+
if (params.emailExist) {
|
|
14
|
+
navigation.navigate('EnterPassword', { email });
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
onRegistrationMethodChange(RegistrationMethod.EMAIL);
|
|
18
|
+
navigation.navigate('SignUp', { email });
|
|
19
|
+
}
|
|
20
|
+
};
|
|
11
21
|
return (_jsxs(Layout, { style: { flex: 1, backgroundColor: '#FFFFFF' }, children: [_jsx(ScreenLayout, { title: "Enter Your Email", buttonProps: {
|
|
12
22
|
loading,
|
|
13
23
|
label: 'Continue',
|
|
14
24
|
onPress: () => {
|
|
15
25
|
Keyboard.dismiss();
|
|
16
26
|
if (!loading && !isInvalidEmail) {
|
|
17
|
-
handleValidateEmail({
|
|
18
|
-
onResult: (params) => {
|
|
19
|
-
if (params.emailExist) {
|
|
20
|
-
navigation.navigate('EnterPassword', { email });
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
onRegistrationMethodChange('email');
|
|
24
|
-
navigation.navigate('SignUp', { email });
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
27
|
+
handleValidateEmail({ onContinue });
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
disabled: isInvalidEmail || loading,
|
|
@@ -4,9 +4,11 @@ import { Button, Flex, Form, PasswordInput, ResponsiveModal, Typography, useForm
|
|
|
4
4
|
import { ScreenLayout } from "../../components/ScreenLayout";
|
|
5
5
|
import { useEnterPassword } from './hooks/internal/useEnterPassword';
|
|
6
6
|
import { SupportDetails } from '../../components/SupportDetails';
|
|
7
|
+
import LoginWithEmailOTP from '../LoginWithEmailOTP';
|
|
7
8
|
import VerifyResetPasswordOTP from '../VerifyResetPasswordOTP';
|
|
8
|
-
const EnterPassword = ({ email, onPressBack,
|
|
9
|
+
const EnterPassword = ({ email, onPressBack, onVerifiedResetPasswordOTP }) => {
|
|
9
10
|
const [showResetPasswordOTPModal, setShowResetPasswordOTPModal] = useState(false);
|
|
11
|
+
const [showLoginWithEmailOTPModal, setShowLoginWithEmailOTPModal] = useState(false);
|
|
10
12
|
const { loading, password, isInvalidPassword, handleSubmit, onPassword, appName } = useEnterPassword();
|
|
11
13
|
const form = useForm({ defaultValues: { password } });
|
|
12
14
|
return (_jsxs(_Fragment, { children: [_jsxs(ScreenLayout, { title: `Hi, Welcome To ${appName}!`, subTitle: email, buttonProps: {
|
|
@@ -20,8 +22,15 @@ const EnterPassword = ({ email, onPressBack, onSignInWithEmailOTP, onVerifiedRes
|
|
|
20
22
|
_jsx(Typography, { type: "body", size: "small", className: "h-1", color: "text-utility-danger-main", children: "Email and password do not match!" }), children: _jsx(PasswordInput, { placeholder: "Enter your password", value: password, showStrengthIndicator: false, className: `border rounded-md px-3 py-2
|
|
21
23
|
${isInvalidPassword ? "border-red-500" : "border-gray-300"}`, ...form.register('password', {
|
|
22
24
|
onChange: (e) => onPassword(e.target.value)
|
|
23
|
-
}) }) }) }), _jsx(Button, { type: "button", size: 'small', variant: 'link', label: "Forgot Password?", className: "px-0 h-auto ml-auto block mt-4", onClick: () => setShowResetPasswordOTPModal(true) }), showResetPasswordOTPModal &&
|
|
24
|
-
|
|
25
|
+
}) }) }) }), _jsx(Button, { type: "button", size: 'small', variant: 'link', label: "Forgot Password?", className: "px-0 h-auto ml-auto block mt-4", onClick: () => setShowResetPasswordOTPModal(true) })] }), _jsxs(Flex, { align: "center", className: "mt-6 mb-6", children: [_jsx(Flex, { className: "flex-1 border-t border-gray-300" }), _jsx(Typography, { type: 'body', size: 'small', className: "text-gray-500 px-4", children: "OR" }), _jsx(Flex, { className: "flex-1 border-t border-gray-300" })] }), _jsx(Button, { label: 'Sign In With OTP', variant: 'secondary', className: 'flex-none', isFullWidth: true, type: "button", onClick: () => setShowLoginWithEmailOTPModal(true) }), _jsx(SupportDetails, {}), showResetPasswordOTPModal &&
|
|
26
|
+
_jsx(VerifyResetPasswordOTPModal, { email: email, show: showResetPasswordOTPModal, hide: () => setShowResetPasswordOTPModal(false), onVerifiedOTP: (sessionToken) => {
|
|
27
|
+
setShowResetPasswordOTPModal(false);
|
|
28
|
+
onVerifiedResetPasswordOTP(sessionToken);
|
|
29
|
+
} }), showLoginWithEmailOTPModal &&
|
|
30
|
+
_jsx(LoginWithEmailOTPModal, { email: email, show: showLoginWithEmailOTPModal, hide: () => setShowLoginWithEmailOTPModal(false) })] }));
|
|
31
|
+
};
|
|
32
|
+
const LoginWithEmailOTPModal = ({ show, hide, email }) => {
|
|
33
|
+
return (_jsx(ResponsiveModal, { open: show, onClose: hide, title: _jsx(Typography, { type: "heading", size: "h6", className: "text-center mb-0", children: "Verify Your Email" }), showCloseButton: false, maskClosable: false, size: 'sm', children: _jsx(LoginWithEmailOTP, { email: email }) }));
|
|
25
34
|
};
|
|
26
35
|
const VerifyResetPasswordOTPModal = ({ show, hide, email, onVerifiedOTP }) => {
|
|
27
36
|
return (_jsx(ResponsiveModal, { title: "Reset Your Password", open: show, onClose: hide, maskClosable: false, showCloseButton: false, size: 'sm', children: _jsx(VerifyResetPasswordOTP, { email: email, onVerifiedOTP: onVerifiedOTP }) }));
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
|
-
import { Flex
|
|
3
|
+
import { Flex } from '@truworth/twc-web-design';
|
|
4
4
|
import { useRouter } from 'next/router';
|
|
5
5
|
import { AdvancedTransitionWrapper } from '../../../../components/AdvancedTransitionWrapper';
|
|
6
6
|
import { useAuthPackageContext } from '../../../../hooks/internal/useAuthPackageContext';
|
|
7
7
|
import EnterEmail from '../../../EnterEmail/index';
|
|
8
8
|
import EnterPassword from '../../../EnterPassword/index';
|
|
9
|
-
import LoginWithEmailOTP from '../../../LoginWithEmailOTP/index';
|
|
10
9
|
import ResetPassword from '../../../ResetPassword/index';
|
|
10
|
+
import SSOSearchOrganization from '../../../SSOLogin/SearchOrganization/index';
|
|
11
|
+
import SSOAuthenticationMethods from '../../../SSOLogin/AuthenticationMethods/index';
|
|
11
12
|
const LoginWebComponent = () => {
|
|
12
13
|
const [email, setEmail] = useState('');
|
|
13
14
|
const [loginState, setLoginState] = useState('EnterEmail');
|
|
14
|
-
const [showLoginWithEmailOTPModal, setShowLoginWithEmailOTPModal] = useState(false);
|
|
15
15
|
const [sessionToken, setSessionToken] = useState('');
|
|
16
|
+
const [selectedClient, setSelectedClient] = useState(null);
|
|
16
17
|
const { LogoComponent } = useAuthPackageContext();
|
|
17
18
|
const router = useRouter();
|
|
18
19
|
const onRedirectToPassword = (email) => {
|
|
@@ -28,33 +29,33 @@ const LoginWebComponent = () => {
|
|
|
28
29
|
const renderStep = () => {
|
|
29
30
|
switch (loginState) {
|
|
30
31
|
case 'EnterEmail':
|
|
31
|
-
return (_jsx(EnterEmail, {
|
|
32
|
+
return (_jsx(EnterEmail, { onContinue: (params) => {
|
|
32
33
|
if (params.emailExist) {
|
|
33
34
|
onRedirectToPassword(params.email);
|
|
34
35
|
}
|
|
35
36
|
else {
|
|
36
37
|
onRedirectToSignUp(params.email);
|
|
37
38
|
}
|
|
38
|
-
} }));
|
|
39
|
+
}, onPressSignInWithSSO: () => setLoginState('SSOSearchOrganization') }));
|
|
39
40
|
case 'EnterPassword':
|
|
40
|
-
return (_jsx(EnterPassword, { email: email, onPressBack: () => setLoginState('EnterEmail'),
|
|
41
|
-
if (email) {
|
|
42
|
-
setShowLoginWithEmailOTPModal(true);
|
|
43
|
-
}
|
|
44
|
-
}, onVerifiedResetPasswordOTP: ({ sessionToken }) => {
|
|
41
|
+
return (_jsx(EnterPassword, { email: email, onPressBack: () => setLoginState('EnterEmail'), onVerifiedResetPasswordOTP: ({ sessionToken }) => {
|
|
45
42
|
setSessionToken(sessionToken);
|
|
46
43
|
setLoginState('ResetPassword');
|
|
47
44
|
} }));
|
|
48
45
|
case 'ResetPassword':
|
|
49
46
|
return (_jsx(ResetPassword, { email: email, sessionToken: sessionToken, onContinue: () => setLoginState('EnterEmail'), onPressBack: () => setLoginState('EnterPassword') }));
|
|
47
|
+
case 'SSOSearchOrganization':
|
|
48
|
+
return (_jsx(SSOSearchOrganization, { onPressBack: () => setLoginState('EnterEmail'), onContinue: (client) => {
|
|
49
|
+
setSelectedClient(client);
|
|
50
|
+
setLoginState('SSOAuthenticationMethods');
|
|
51
|
+
} }));
|
|
52
|
+
case 'SSOAuthenticationMethods':
|
|
53
|
+
return selectedClient && (_jsx(SSOAuthenticationMethods, { onPressBack: () => setLoginState('EnterEmail'), client: selectedClient }));
|
|
50
54
|
default:
|
|
51
55
|
return null;
|
|
52
56
|
}
|
|
53
57
|
};
|
|
54
|
-
return (_jsx(AdvancedTransitionWrapper, { type: 'slide', duration: 0.5, children: _jsxs(Flex, { direction: 'column', justify: 'center',
|
|
55
|
-
&& LogoComponent, renderStep()
|
|
58
|
+
return (_jsx(AdvancedTransitionWrapper, { type: 'slide', duration: 0.5, children: _jsxs(Flex, { direction: 'column', justify: 'center', className: `lg:w-[70%] lg:h-screen mx-auto h-full my-10`, children: [React.isValidElement(LogoComponent)
|
|
59
|
+
&& LogoComponent, renderStep()] }) }));
|
|
56
60
|
};
|
|
57
61
|
export { LoginWebComponent };
|
|
58
|
-
const LoginWithEmailOTPModal = ({ show, hide, email }) => {
|
|
59
|
-
return (_jsx(ResponsiveModal, { open: show, onClose: hide, title: _jsx(Typography, { type: "heading", size: "h6", className: "text-center mb-0", children: "Verify Your Email" }), showCloseButton: false, maskClosable: false, size: 'sm', children: _jsx(LoginWithEmailOTP, { email: email }) }));
|
|
60
|
-
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const SSOAuthWebView = () => {
|
|
2
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3
|
+
if (typeof window !== 'undefined') {
|
|
4
|
+
console.warn("[@truworth/twc-auth] SSOAuthWebView is only available for native app screens");
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
return null;
|
|
8
|
+
};
|
|
9
|
+
export default SSOAuthWebView;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { WebView } from '@truworth/twc-rn-common';
|
|
3
|
+
import { Layout } from '@ui-kitten/components';
|
|
4
|
+
import { Text } from 'react-native';
|
|
5
|
+
import parse from 'url-parse';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
const SSOAuthWebView = ({ navigation, route }) => {
|
|
8
|
+
const { clientId, authenticationUrl, redirectUri } = route.params;
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
return (_jsxs(Layout, { style: { flex: 1 }, children: [error && (_jsx(Layout, { style: { padding: 16, backgroundColor: '#fee' }, children: _jsx(Text, { style: { color: 'red' }, children: error }) })), _jsx(WebView, { source: { uri: authenticationUrl }, style: { flex: 1 }, onError: (syntheticEvent) => {
|
|
11
|
+
const { nativeEvent } = syntheticEvent;
|
|
12
|
+
setError(`Failed to load authentication page: ${nativeEvent.description}`);
|
|
13
|
+
}, onHttpError: (syntheticEvent) => {
|
|
14
|
+
const { nativeEvent } = syntheticEvent;
|
|
15
|
+
setError(`Authentication provider error: ${nativeEvent.statusCode}`);
|
|
16
|
+
}, onNavigationStateChange: (navState) => {
|
|
17
|
+
setError(null);
|
|
18
|
+
const currentUrl = parse(navState.url, true).href;
|
|
19
|
+
const authUrl = parse(authenticationUrl, true).href;
|
|
20
|
+
if (currentUrl != authUrl && navState.url.includes(redirectUri)) {
|
|
21
|
+
const query = parse(navState.url, true).query;
|
|
22
|
+
const { code } = query;
|
|
23
|
+
navigation.replace('SSOCallback', { clientId, code });
|
|
24
|
+
}
|
|
25
|
+
} })] }));
|
|
26
|
+
};
|
|
27
|
+
export default SSOAuthWebView;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from "react";
|
|
2
|
+
import { axiosClient } from "../../../../../api/axiosClient";
|
|
3
|
+
import { showMessage } from "../../../../../helpers/show-message";
|
|
4
|
+
const useSSOAuthenticationMethods = () => {
|
|
5
|
+
const [loading, setLoading] = useState(false);
|
|
6
|
+
const isMountedRef = useRef(true);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
return () => {
|
|
9
|
+
isMountedRef.current = false;
|
|
10
|
+
};
|
|
11
|
+
}, []);
|
|
12
|
+
const initiateSSOLogin = ({ clientId, onSSOLoginInitiated }) => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
axiosClient({
|
|
15
|
+
url: `/auth/login-sso/${clientId}/initiate`,
|
|
16
|
+
method: 'POST',
|
|
17
|
+
}).then((res) => {
|
|
18
|
+
if (!isMountedRef.current)
|
|
19
|
+
return;
|
|
20
|
+
const { authenticationUrl, redirectUri } = res.data;
|
|
21
|
+
onSSOLoginInitiated({ clientId, authenticationUrl, redirectUri });
|
|
22
|
+
}).catch((error) => {
|
|
23
|
+
if (!isMountedRef.current)
|
|
24
|
+
return;
|
|
25
|
+
const message = error?.response?.data?.errors?.[0]?.message ??
|
|
26
|
+
error?.response?.data?.message ??
|
|
27
|
+
error?.message ??
|
|
28
|
+
'Something went wrong';
|
|
29
|
+
showMessage({ message });
|
|
30
|
+
}).finally(() => {
|
|
31
|
+
if (isMountedRef.current) {
|
|
32
|
+
setLoading(false);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
return { loading, initiateSSOLogin };
|
|
37
|
+
};
|
|
38
|
+
export { useSSOAuthenticationMethods };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Flex, Typography } from "@truworth/twc-web-design";
|
|
3
|
+
import { useSSOAuthenticationMethods } from "./hooks/internal/useSSOAuthenticationMethods";
|
|
4
|
+
import { useAuthPackageContext } from "../../../hooks/internal/useAuthPackageContext";
|
|
5
|
+
import { ScreenLayout } from "../../../components/ScreenLayout";
|
|
6
|
+
import { CDN_IMAGES_URL } from "@truworth/twc-web-common";
|
|
7
|
+
import { showMessage } from "../../../helpers/show-message";
|
|
8
|
+
import React from "react";
|
|
9
|
+
const SSOAuthenticationMethods = ({ client, onPressBack }) => {
|
|
10
|
+
const { loading, initiateSSOLogin } = useSSOAuthenticationMethods();
|
|
11
|
+
const { LogoComponent } = useAuthPackageContext();
|
|
12
|
+
const renderLogo = () => {
|
|
13
|
+
if (!LogoComponent) {
|
|
14
|
+
return (_jsx("img", { width: 160, height: 35, className: 'md:mt-0 mt-6 md:h-[40px] h-[30px]', src: `${CDN_IMAGES_URL ?? ''}/new-twc_logo.svg` }));
|
|
15
|
+
}
|
|
16
|
+
// If it's already a React element, return it as is
|
|
17
|
+
if (React.isValidElement(LogoComponent)) {
|
|
18
|
+
return LogoComponent;
|
|
19
|
+
}
|
|
20
|
+
// If it's a function component, render it
|
|
21
|
+
if (typeof LogoComponent === 'function') {
|
|
22
|
+
const Component = LogoComponent;
|
|
23
|
+
return _jsx(Component, {});
|
|
24
|
+
}
|
|
25
|
+
// Fallback to default logo
|
|
26
|
+
return (_jsx("img", { width: 160, height: 35, className: 'md:mt-0 mt-6 md:h-[40px] h-[30px]', src: `${CDN_IMAGES_URL ?? ''}/new-twc_logo.svg` }));
|
|
27
|
+
};
|
|
28
|
+
const onSSOLoginInitiated = (result) => {
|
|
29
|
+
try {
|
|
30
|
+
localStorage.setItem('clientId', String(result.clientId));
|
|
31
|
+
const u = new URL(result.authenticationUrl);
|
|
32
|
+
window.location.href = u.toString();
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
showMessage({ message: 'Failed to initialize SSO login. Please try again.' });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
return (_jsx(ScreenLayout, { title: _jsxs(Flex, { direction: "column", children: [client?.image ?
|
|
40
|
+
_jsx("img", { src: client?.image, width: 175, height: 117, alt: `${client?.name ?? 'Client'} logo` })
|
|
41
|
+
: renderLogo(), _jsx(Typography, { type: "heading", size: "h5", className: "my-6", children: "Select how to sign-in" }), client?.ssoEnabled &&
|
|
42
|
+
_jsxs(_Fragment, { children: [_jsx(Button, { label: "Login with SSO", isFullWidth: true, variant: "primary", onClick: () => initiateSSOLogin({ clientId: client.id, onSSOLoginInitiated }), loading: loading }), _jsx(Typography, { type: "body", size: "large", className: "mt-6 text-gray-600", children: "The above option is recommended for quick access" }), _jsxs(Flex, { align: "center", className: "my-4", children: [_jsx(Flex, { className: "flex-1 border-t border-gray-300" }), _jsx(Typography, { type: 'body', size: 'small', className: "text-gray-500 px-4", children: "OR" }), _jsx(Flex, { className: "flex-1 border-t border-gray-300" })] })] })] }), onPressBack: onPressBack, buttonProps: {
|
|
43
|
+
label: "Login with Email & Password",
|
|
44
|
+
variant: "secondary",
|
|
45
|
+
onClick: onPressBack,
|
|
46
|
+
} }));
|
|
47
|
+
};
|
|
48
|
+
export default SSOAuthenticationMethods;
|