@truworth/twc-auth 3.0.12 → 3.0.14
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/src/constants/social-login-options.js +0 -4
- package/build/src/enums/loginMethod.enum.js +0 -1
- package/build/src/enums/socialLogins.enum.js +0 -1
- package/build/src/screens/EnterEmail/hooks/internal/useEnterEmail.js +0 -1
- package/build/src/screens/EnterEmail/index.js +1 -3
- package/build/src/screens/SSOLogin/AuthenticationMethods/hooks/internal/useSSOAuthenticationMethods.js +27 -3
- package/build/src/screens/SSOLogin/AuthenticationMethods/index.js +10 -8
- package/build/src/screens/SSOLogin/AuthenticationMethods/index.native.js +20 -5
- package/build/src/screens/SignUp/hooks/internal/useSignUp.js +0 -1
- package/build/src/screens/Welcome/SocialAuth/commonSocialAuth.js +1 -13
- package/build/src/screens/Welcome/SocialAuth/hooks/useSocialAuth.native.js +1 -47
- package/build/src/screens/Welcome/SocialAuth/hooks/useSocialAuth.web.js +0 -4
- package/build/src/screens/Welcome/index.native.js +1 -3
- package/build/types/enums/loginMethod.enum.d.ts +0 -1
- package/build/types/enums/socialLogins.enum.d.ts +0 -1
- package/build/types/screens/SSOLogin/AuthenticationMethods/hooks/internal/useSSOAuthenticationMethods.d.ts +7 -1
- package/build/types/screens/SignUp/hooks/internal/useSignUp.d.ts +1 -1
- package/build/types/screens/Welcome/SocialAuth/commonSocialAuth.d.ts +0 -7
- package/build/types/screens/Welcome/SocialAuth/hooks/useSocialAuth.native.d.ts +0 -1
- package/build/types/screens/Welcome/SocialAuth/hooks/useSocialAuth.web.d.ts +0 -2
- package/package.json +1 -2
- package/build/src/screens/Welcome/SocialAuth/hooks/web/useFacebookAuth.web.js +0 -115
- package/build/types/screens/Welcome/SocialAuth/hooks/web/useFacebookAuth.web.d.ts +0 -5
|
@@ -4,10 +4,6 @@ const socialLoginOptions = [
|
|
|
4
4
|
type: SocialLoginsEnum.Google,
|
|
5
5
|
iconImageUrl: `https://cdn-thewellnesscorner.s3.amazonaws.com/twc-web-images/template/google-icon.png`,
|
|
6
6
|
},
|
|
7
|
-
{
|
|
8
|
-
type: SocialLoginsEnum.Facebook,
|
|
9
|
-
iconImageUrl: `https://cdn-thewellnesscorner.s3.amazonaws.com/twc-web-images/template/facebook-icon.png`,
|
|
10
|
-
},
|
|
11
7
|
{
|
|
12
8
|
type: SocialLoginsEnum.Apple,
|
|
13
9
|
iconImageUrl: `https://cdn-thewellnesscorner.s3.amazonaws.com/twc-web-images/template/apple-icon.png`,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export var LoginMethodCode;
|
|
2
2
|
(function (LoginMethodCode) {
|
|
3
3
|
LoginMethodCode[LoginMethodCode["Email"] = 1] = "Email";
|
|
4
|
-
LoginMethodCode[LoginMethodCode["Facebook"] = 2] = "Facebook";
|
|
5
4
|
LoginMethodCode[LoginMethodCode["Google"] = 3] = "Google";
|
|
6
5
|
LoginMethodCode[LoginMethodCode["Apple"] = 4] = "Apple";
|
|
7
6
|
LoginMethodCode[LoginMethodCode["SSO"] = 5] = "SSO";
|
|
@@ -33,7 +33,6 @@ const useEnterEmail = () => {
|
|
|
33
33
|
const loginCode = Number(loginType);
|
|
34
34
|
if (emailExist && loginCode !== LoginMethodCode.Email) {
|
|
35
35
|
const loginMethodMap = {
|
|
36
|
-
[LoginMethodCode.Facebook]: "Facebook",
|
|
37
36
|
[LoginMethodCode.Google]: "Google",
|
|
38
37
|
[LoginMethodCode.Apple]: "Apple",
|
|
39
38
|
[LoginMethodCode.SSO]: "SSO",
|
|
@@ -11,7 +11,7 @@ import { useSocialAuth } from '../Welcome/SocialAuth/hooks/useSocialAuth.web';
|
|
|
11
11
|
import { SocialLoginsEnum } from '../../enums';
|
|
12
12
|
import _ from 'lodash';
|
|
13
13
|
const EnterEmail = ({ onContinue, onPressSignInWithSSO }) => {
|
|
14
|
-
const { loginWithGoogle
|
|
14
|
+
const { loginWithGoogle } = useSocialAuth();
|
|
15
15
|
const { email, isEmailValid, handleEmailChange, appName, handleEmailExists, loading, loginConflictTitle, loginConflictDescription, isLoginConflictModalVisible, setIsLoginConflictModalVisible, } = useEnterEmail();
|
|
16
16
|
const { showSocialLoginModal, setShowSocialLoginModal, socialLoginType, setSocialLoginType, isSocialLoginEnabled, socialLoginConfig, } = useWelcome();
|
|
17
17
|
const form = useForm({ defaultValues: { email } });
|
|
@@ -20,8 +20,6 @@ const EnterEmail = ({ onContinue, onPressSignInWithSSO }) => {
|
|
|
20
20
|
switch (socialLoginType) {
|
|
21
21
|
case SocialLoginsEnum.Google:
|
|
22
22
|
return loginWithGoogle();
|
|
23
|
-
case SocialLoginsEnum.Facebook:
|
|
24
|
-
return loginWithFacebook();
|
|
25
23
|
default:
|
|
26
24
|
return;
|
|
27
25
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useState, useRef, useEffect } from "react";
|
|
1
|
+
import { useState, useRef, useEffect, useMemo } from "react";
|
|
2
2
|
import { axiosClient } from "../../../../../api/axiosClient";
|
|
3
3
|
import { showMessage } from "../../../../../helpers/show-message";
|
|
4
|
-
const useSSOAuthenticationMethods = () => {
|
|
4
|
+
const useSSOAuthenticationMethods = ({ client }) => {
|
|
5
5
|
const [loading, setLoading] = useState(false);
|
|
6
6
|
const isMountedRef = useRef(true);
|
|
7
7
|
useEffect(() => {
|
|
@@ -34,6 +34,30 @@ const useSSOAuthenticationMethods = () => {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
const headingText = useMemo(() => {
|
|
38
|
+
if (client?.ssoEnabled && client?.mobileLoginEnabled) {
|
|
39
|
+
return `Choose how to sign in`;
|
|
40
|
+
}
|
|
41
|
+
if (client?.ssoEnabled) {
|
|
42
|
+
return `Sign in with your organization account`;
|
|
43
|
+
}
|
|
44
|
+
if (client?.mobileLoginEnabled) {
|
|
45
|
+
return `Sign in with your mobile number`;
|
|
46
|
+
}
|
|
47
|
+
return 'No Single Sign-On methods are available';
|
|
48
|
+
}, [client?.ssoEnabled, client?.mobileLoginEnabled]);
|
|
49
|
+
const subHeadingText = useMemo(() => {
|
|
50
|
+
if (!client?.ssoEnabled && !client?.mobileLoginEnabled) {
|
|
51
|
+
return 'Your organization has not configured any single sign-on methods yet. Please contact your administrator.';
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}, [client?.ssoEnabled, client?.mobileLoginEnabled]);
|
|
55
|
+
return {
|
|
56
|
+
loading,
|
|
57
|
+
initiateSSOLogin,
|
|
58
|
+
headingText,
|
|
59
|
+
subHeadingText,
|
|
60
|
+
hasMultipleLoginOptions: client?.ssoEnabled && client?.mobileLoginEnabled,
|
|
61
|
+
};
|
|
38
62
|
};
|
|
39
63
|
export { useSSOAuthenticationMethods };
|
|
@@ -6,9 +6,9 @@ import { ScreenLayout } from "../../../components/ScreenLayout";
|
|
|
6
6
|
import { CDN_IMAGES_URL } from "../../../constants/cdn-url";
|
|
7
7
|
import { showMessage } from "../../../helpers/show-message";
|
|
8
8
|
import React from "react";
|
|
9
|
-
import { KeyRound,
|
|
9
|
+
import { KeyRound, Smartphone } from "lucide-react";
|
|
10
10
|
const SSOAuthenticationMethods = ({ client, onPressBack, handleMobileLogin }) => {
|
|
11
|
-
const { loading, initiateSSOLogin } = useSSOAuthenticationMethods();
|
|
11
|
+
const { loading, initiateSSOLogin, hasMultipleLoginOptions, headingText, subHeadingText } = useSSOAuthenticationMethods({ client });
|
|
12
12
|
const { LogoComponent } = useAuthPackageContext();
|
|
13
13
|
const renderLogo = () => {
|
|
14
14
|
if (!LogoComponent) {
|
|
@@ -40,11 +40,13 @@ const SSOAuthenticationMethods = ({ client, onPressBack, handleMobileLogin }) =>
|
|
|
40
40
|
};
|
|
41
41
|
return (_jsx(ScreenLayout, { onPressBack: onPressBack, title: _jsxs(Flex, { direction: "column", children: [client?.image ?
|
|
42
42
|
_jsx("img", { src: client?.image, width: 175, height: 117, alt: `${client?.name ?? 'Client'} logo` })
|
|
43
|
-
: renderLogo(), _jsx(Typography, { type: "heading", size: "h5", className: "
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
: renderLogo(), _jsx(Typography, { type: "heading", size: "h5", className: "mb-4 mt-6", children: headingText }), subHeadingText &&
|
|
44
|
+
_jsx(Typography, { type: "body", size: "large", className: "text-gray-600", children: subHeadingText }), client?.ssoEnabled &&
|
|
45
|
+
_jsx(Button, { label: "Login with SSO", isFullWidth: true, variant: "primary", leftIcon: _jsx(KeyRound, {}), onClick: () => initiateSSOLogin({
|
|
46
|
+
clientId: client.id,
|
|
47
|
+
onSSOLoginInitiated
|
|
48
|
+
}), loading: loading }), hasMultipleLoginOptions &&
|
|
49
|
+
_jsxs(_Fragment, { children: [_jsx(Typography, { type: "body", size: "large", className: "mt-6 text-gray-600", children: "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" })] })] }), client?.mobileLoginEnabled &&
|
|
50
|
+
_jsx(Button, { label: "Login with Mobile Number", isFullWidth: true, className: "mt-6", leftIcon: _jsx(Smartphone, {}), variant: "secondary", onClick: handleMobileLogin })] }) }));
|
|
49
51
|
};
|
|
50
52
|
export default SSOAuthenticationMethods;
|
|
@@ -13,9 +13,9 @@ const { primary, gray } = Colors;
|
|
|
13
13
|
const SSOAuthenticationMethods = ({ route }) => {
|
|
14
14
|
const { client } = route.params;
|
|
15
15
|
const [aspectRatio, setAspectRatio] = useState(1);
|
|
16
|
-
const { loading, initiateSSOLogin } = useSSOAuthenticationMethods();
|
|
17
|
-
const { LogoComponent } = useAuthPackageContext();
|
|
16
|
+
const { loading, initiateSSOLogin, hasMultipleLoginOptions, headingText, subHeadingText } = useSSOAuthenticationMethods({ client });
|
|
18
17
|
const navigation = useNavigation();
|
|
18
|
+
const { LogoComponent } = useAuthPackageContext();
|
|
19
19
|
useEffect(() => {
|
|
20
20
|
if (client.image) {
|
|
21
21
|
Image.getSize(client.image, (width, height) => {
|
|
@@ -52,8 +52,23 @@ const SSOAuthenticationMethods = ({ route }) => {
|
|
|
52
52
|
};
|
|
53
53
|
return (_jsx(ScreenLayout, { title: "", containerStyle: { flex: 1, backgroundColor: primary.white }, children: _jsxs(View, { style: { flex: 1, justifyContent: 'center' }, children: [client.image ?
|
|
54
54
|
_jsx(FastImage, { source: { uri: client.image }, resizeMode: 'contain', style: { width: 180, aspectRatio: aspectRatio, alignSelf: 'center', marginTop: -150 } })
|
|
55
|
-
: renderLogo(), _jsx(Text, { style: { textAlign: 'center', fontSize:
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
: renderLogo(), _jsx(Text, { style: { textAlign: 'center', fontSize: 18, fontWeight: '600', color: gray.gray_700, marginTop: 30, lineHeight: 32 }, children: headingText }), subHeadingText &&
|
|
56
|
+
_jsx(Text, { style: {
|
|
57
|
+
textAlign: 'center',
|
|
58
|
+
fontSize: 16,
|
|
59
|
+
lineHeight: 22,
|
|
60
|
+
color: gray.gray_600,
|
|
61
|
+
marginTop: 12,
|
|
62
|
+
marginHorizontal: 32,
|
|
63
|
+
}, children: subHeadingText }), client?.ssoEnabled &&
|
|
64
|
+
_jsx(RoundedButton, { loading: loading, type: 'primary', label: 'Login with SSO', size: 'large', containerStyle: { marginTop: 18 }, onPress: () => initiateSSOLogin({
|
|
65
|
+
clientId: client.id,
|
|
66
|
+
onSSOLoginInitiated,
|
|
67
|
+
}), leftIcon: 'key-outline' }), hasMultipleLoginOptions &&
|
|
68
|
+
_jsxs(_Fragment, { children: [_jsx(Text, { style: { textAlign: 'center', fontSize: 14, color: gray.gray_700, marginTop: 20, }, children: "Recommended for quick access" }), _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', marginTop: 30, marginHorizontal: 30 }, children: [_jsx(View, { style: { flex: 1, height: 1, backgroundColor: gray.gray_200, } }), _jsx(Text, { style: { width: 50, textAlign: 'center', color: gray.gray_500, fontSize: 16, }, children: "OR" }), _jsx(View, { style: { flex: 1, height: 1, backgroundColor: gray.gray_200, } })] })] }), client?.mobileLoginEnabled &&
|
|
69
|
+
_jsx(RoundedButton, { type: 'secondary', label: 'Login with Mobile Number', size: 'large', containerStyle: {
|
|
70
|
+
marginHorizontal: 16,
|
|
71
|
+
marginTop: 30
|
|
72
|
+
}, onPress: () => navigation.navigate('EnterMobile'), leftIcon: 'phone-portrait-outline' })] }) }));
|
|
58
73
|
};
|
|
59
74
|
export default SSOAuthenticationMethods;
|
|
@@ -16,7 +16,6 @@ export var SocialAuthStatus;
|
|
|
16
16
|
// ============================================
|
|
17
17
|
const EXISTING_LOGIN_TYPE = {
|
|
18
18
|
[LoginMethodCode.Email]: 'Email Address',
|
|
19
|
-
[LoginMethodCode.Facebook]: 'Facebook Account',
|
|
20
19
|
[LoginMethodCode.Google]: 'Google Account',
|
|
21
20
|
[LoginMethodCode.Apple]: 'Apple ID',
|
|
22
21
|
};
|
|
@@ -26,11 +25,6 @@ const PROVIDER_CONFIG = {
|
|
|
26
25
|
tokenKey: 'token',
|
|
27
26
|
loginMethodCode: LoginMethodCode.Google,
|
|
28
27
|
},
|
|
29
|
-
[SocialLoginsEnum.Facebook]: {
|
|
30
|
-
endpoint: '/auth/facebook',
|
|
31
|
-
tokenKey: 'token',
|
|
32
|
-
loginMethodCode: LoginMethodCode.Facebook,
|
|
33
|
-
},
|
|
34
28
|
[SocialLoginsEnum.Apple]: {
|
|
35
29
|
endpoint: '/auth/apple/appleid-exists',
|
|
36
30
|
tokenKey: 'token',
|
|
@@ -61,7 +55,7 @@ const verifyLoginType = async (email, attemptedLoginCode) => {
|
|
|
61
55
|
};
|
|
62
56
|
/**
|
|
63
57
|
* Generic handler for social authentication
|
|
64
|
-
* @param provider - Social provider (google,
|
|
58
|
+
* @param provider - Social provider (google, apple)
|
|
65
59
|
* @param email - User's email
|
|
66
60
|
* @param identityToken - Provider's identity token
|
|
67
61
|
* @param platform - Platform (web, ios, android)
|
|
@@ -113,12 +107,6 @@ const handleSocialAuth = async (provider, email, identityToken, platform) => {
|
|
|
113
107
|
export const handleGoogleAuth = async ({ email, googleIdentityToken, platform, }) => {
|
|
114
108
|
return handleSocialAuth(SocialLoginsEnum.Google, email, googleIdentityToken, platform);
|
|
115
109
|
};
|
|
116
|
-
/**
|
|
117
|
-
* Handles Facebook authentication
|
|
118
|
-
*/
|
|
119
|
-
export const handleFacebookAuth = async ({ email, facebookIdentityToken, platform }) => {
|
|
120
|
-
return handleSocialAuth(SocialLoginsEnum.Facebook, email, facebookIdentityToken, platform);
|
|
121
|
-
};
|
|
122
110
|
/**
|
|
123
111
|
* Handles Apple authentication
|
|
124
112
|
*/
|
|
@@ -3,10 +3,9 @@ import { Alert, Linking, Platform } from "react-native";
|
|
|
3
3
|
import { useAuthPackageContext } from "../../../../hooks/internal/useAuthPackageContext";
|
|
4
4
|
import { useNavigation } from "@react-navigation/native";
|
|
5
5
|
import { GoogleSignin } from "@react-native-google-signin/google-signin";
|
|
6
|
-
import { handleAppleAuth,
|
|
6
|
+
import { handleAppleAuth, handleGoogleAuth, SocialAuthStatus } from "../commonSocialAuth";
|
|
7
7
|
import { RegistrationMethod, SocialLoginsEnum } from "../../../../enums";
|
|
8
8
|
import { showMessage } from "../../../../helpers/show-message";
|
|
9
|
-
import { AccessToken, GraphRequest, GraphRequestManager, LoginManager } from "react-native-fbsdk-next";
|
|
10
9
|
import appleAuth from '@invertase/react-native-apple-authentication';
|
|
11
10
|
import { axiosClient } from "../../../../api/axiosClient";
|
|
12
11
|
const useSocialAuth = () => {
|
|
@@ -47,49 +46,6 @@ const useSocialAuth = () => {
|
|
|
47
46
|
setLoading(false);
|
|
48
47
|
}
|
|
49
48
|
}, [googleAppId]);
|
|
50
|
-
const loginWithFacebook = useCallback(async () => {
|
|
51
|
-
try {
|
|
52
|
-
const facebookResponse = await LoginManager.logInWithPermissions(['public_profile', 'email']);
|
|
53
|
-
if (facebookResponse.isCancelled) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
setLoading(true);
|
|
57
|
-
const fbAccessToken = await AccessToken.getCurrentAccessToken();
|
|
58
|
-
const profile = await new Promise((resolve, reject) => {
|
|
59
|
-
new GraphRequestManager().addRequest(new GraphRequest('/me', {
|
|
60
|
-
accessToken: fbAccessToken?.accessToken,
|
|
61
|
-
parameters: { fields: { string: 'email,name' } },
|
|
62
|
-
}, (err, res) => (err ? reject(err) : resolve(res)))).start();
|
|
63
|
-
});
|
|
64
|
-
if (!profile.email || !profile.id) {
|
|
65
|
-
return showMessage({
|
|
66
|
-
message: "Facebook login failed",
|
|
67
|
-
type: "error"
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
const nameParts = profile.name?.split(' ') || [];
|
|
71
|
-
const firstName = nameParts[0] || undefined;
|
|
72
|
-
const lastName = nameParts.slice(1).join(' ') || undefined;
|
|
73
|
-
const result = await handleFacebookAuth({
|
|
74
|
-
email: profile.email,
|
|
75
|
-
facebookIdentityToken: fbAccessToken?.accessToken ?? '',
|
|
76
|
-
platform: Platform.OS === "ios" ? "ios" : "android",
|
|
77
|
-
});
|
|
78
|
-
return handleSocialAuthResult(result, {
|
|
79
|
-
email: profile.email,
|
|
80
|
-
firstName,
|
|
81
|
-
lastName,
|
|
82
|
-
fbUserId: profile.id
|
|
83
|
-
}, SocialLoginsEnum.Facebook);
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
console.log("Facebook login failed:", err);
|
|
87
|
-
return { error: err };
|
|
88
|
-
}
|
|
89
|
-
finally {
|
|
90
|
-
setLoading(false);
|
|
91
|
-
}
|
|
92
|
-
}, []);
|
|
93
49
|
const loginWithApple = useCallback(async () => {
|
|
94
50
|
try {
|
|
95
51
|
const appleAuthResponse = await appleAuth.performRequest({
|
|
@@ -156,7 +112,6 @@ const useSocialAuth = () => {
|
|
|
156
112
|
}, []);
|
|
157
113
|
const providerCleanup = {
|
|
158
114
|
google: () => GoogleSignin.signOut(),
|
|
159
|
-
facebook: () => LoginManager.logOut(),
|
|
160
115
|
apple: () => Promise.resolve(), // Apple doesn't need explicit cleanup
|
|
161
116
|
};
|
|
162
117
|
const handleSocialAuthResult = async (result, userData, providerName) => {
|
|
@@ -180,7 +135,6 @@ const useSocialAuth = () => {
|
|
|
180
135
|
return {
|
|
181
136
|
loading,
|
|
182
137
|
loginWithGoogle,
|
|
183
|
-
loginWithFacebook,
|
|
184
138
|
loginWithApple
|
|
185
139
|
};
|
|
186
140
|
};
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { useFacebookAuth } from "./web/useFacebookAuth.web";
|
|
2
1
|
import { useGoogleAuth } from "./web/useGoogleAuth.web";
|
|
3
2
|
const useSocialAuth = () => {
|
|
4
3
|
const { loginWithGoogle, googleSignOut } = useGoogleAuth();
|
|
5
|
-
const { loginWithFacebook, facebookSignOut } = useFacebookAuth();
|
|
6
4
|
return {
|
|
7
5
|
loginWithGoogle,
|
|
8
6
|
googleSignOut,
|
|
9
|
-
loginWithFacebook,
|
|
10
|
-
facebookSignOut
|
|
11
7
|
};
|
|
12
8
|
};
|
|
13
9
|
export { useSocialAuth };
|
|
@@ -13,7 +13,7 @@ import { SocialLoginsEnum } from '../../enums';
|
|
|
13
13
|
import FastImage from 'react-native-fast-image';
|
|
14
14
|
const { gray } = Colors;
|
|
15
15
|
const Welcome = ({ navigation }) => {
|
|
16
|
-
const { loading,
|
|
16
|
+
const { loading, loginWithGoogle, loginWithApple } = useSocialAuth();
|
|
17
17
|
const { LogoComponent, isSocialLoginEnabled, showSocialLoginModal, setShowSocialLoginModal, socialLoginType, setSocialLoginType, socialLoginConfig, onLaunchAuthSession, } = useWelcome();
|
|
18
18
|
useFocusEffect(useCallback(() => {
|
|
19
19
|
onLaunchAuthSession?.();
|
|
@@ -41,8 +41,6 @@ const Welcome = ({ navigation }) => {
|
|
|
41
41
|
switch (socialLoginType) {
|
|
42
42
|
case SocialLoginsEnum.Google:
|
|
43
43
|
return loginWithGoogle();
|
|
44
|
-
case SocialLoginsEnum.Facebook:
|
|
45
|
-
return loginWithFacebook();
|
|
46
44
|
case SocialLoginsEnum.Apple:
|
|
47
45
|
return loginWithApple();
|
|
48
46
|
default:
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { SSOInitiationData } from "../../types";
|
|
2
|
-
|
|
2
|
+
import type { Client } from "../../../../../types/types";
|
|
3
|
+
declare const useSSOAuthenticationMethods: ({ client }: {
|
|
4
|
+
client: Client;
|
|
5
|
+
}) => {
|
|
3
6
|
loading: boolean;
|
|
4
7
|
initiateSSOLogin: ({ clientId, onSSOLoginInitiated }: {
|
|
5
8
|
clientId: number;
|
|
6
9
|
onSSOLoginInitiated: (data: SSOInitiationData) => void;
|
|
7
10
|
}) => void;
|
|
11
|
+
headingText: string;
|
|
12
|
+
subHeadingText: string | null;
|
|
13
|
+
hasMultipleLoginOptions: boolean;
|
|
8
14
|
};
|
|
9
15
|
export { useSSOAuthenticationMethods };
|
|
@@ -37,7 +37,7 @@ declare const useSignUp: () => {
|
|
|
37
37
|
handleSubmit: ({ onProceed }: {
|
|
38
38
|
onProceed: () => void;
|
|
39
39
|
}) => Promise<void>;
|
|
40
|
-
getLoginTypeText: (loginType: number) => "
|
|
40
|
+
getLoginTypeText: (loginType: number) => "Google" | "Apple" | "Email" | "Microsoft";
|
|
41
41
|
disabled: boolean;
|
|
42
42
|
registrationMethod: import("../../../../types/types").RegistrationMethod;
|
|
43
43
|
onRegistrationMethodChange: (method: import("../../../../types/types").RegistrationMethod) => void;
|
|
@@ -12,9 +12,6 @@ interface BaseSocialLoginParams {
|
|
|
12
12
|
export interface GoogleLoginParams extends BaseSocialLoginParams {
|
|
13
13
|
googleIdentityToken: string;
|
|
14
14
|
}
|
|
15
|
-
export interface FacebookLoginParams extends BaseSocialLoginParams {
|
|
16
|
-
facebookIdentityToken: string;
|
|
17
|
-
}
|
|
18
15
|
export interface AppleLoginParams extends BaseSocialLoginParams {
|
|
19
16
|
appleIdentityToken: string;
|
|
20
17
|
}
|
|
@@ -39,10 +36,6 @@ export type SocialAuthResult = {
|
|
|
39
36
|
* Handles Google authentication
|
|
40
37
|
*/
|
|
41
38
|
export declare const handleGoogleAuth: ({ email, googleIdentityToken, platform, }: GoogleLoginParams) => Promise<SocialAuthResult>;
|
|
42
|
-
/**
|
|
43
|
-
* Handles Facebook authentication
|
|
44
|
-
*/
|
|
45
|
-
export declare const handleFacebookAuth: ({ email, facebookIdentityToken, platform }: FacebookLoginParams) => Promise<SocialAuthResult>;
|
|
46
39
|
/**
|
|
47
40
|
* Handles Apple authentication
|
|
48
41
|
*/
|
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": "3.0.
|
|
7
|
+
"version": "3.0.14",
|
|
8
8
|
"main": "build/src/index.js",
|
|
9
9
|
"types": "build/types/index.d.ts",
|
|
10
10
|
"files": [
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"react-lottie": "^1.2.3",
|
|
54
54
|
"react-native": "0.80.2",
|
|
55
55
|
"react-native-fast-image": "8.6.3",
|
|
56
|
-
"react-native-fbsdk-next": "13.4.1",
|
|
57
56
|
"react-native-linear-gradient": "2.8.3",
|
|
58
57
|
"react-native-gesture-handler": "2.28.0",
|
|
59
58
|
"react-native-modalize": "2.1.1",
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { useEffect, useCallback, useState } from "react";
|
|
2
|
-
import { useAuthPackageContext } from "../../../../../hooks/internal/useAuthPackageContext";
|
|
3
|
-
import { RegistrationMethod } from "../../../../../enums";
|
|
4
|
-
import { handleFacebookAuth } from "../../commonSocialAuth";
|
|
5
|
-
import { showMessage } from "../../../../../helpers/show-message";
|
|
6
|
-
import { useNavigator } from "../../../../../hooks/useNavigator";
|
|
7
|
-
export const useFacebookAuth = () => {
|
|
8
|
-
const [error, setError] = useState(null);
|
|
9
|
-
const { onLogin, socialLoginConfig, onRegistrationMethodChange, onTokenChange } = useAuthPackageContext();
|
|
10
|
-
const navigator = useNavigator();
|
|
11
|
-
const facebookAppId = socialLoginConfig?.facebook?.webClientId;
|
|
12
|
-
// Load Facebook SDK once
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (!facebookAppId) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
(function (d, s, id) {
|
|
18
|
-
var js, fjs = d.getElementsByTagName(s)[0];
|
|
19
|
-
if (d.getElementById(id)) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
js = d.createElement(s);
|
|
23
|
-
js.id = id;
|
|
24
|
-
js.src = "https://connect.facebook.net/en_US/sdk.js";
|
|
25
|
-
if (fjs && fjs.parentNode) {
|
|
26
|
-
fjs.parentNode.insertBefore(js, fjs);
|
|
27
|
-
}
|
|
28
|
-
}(document, 'script', 'facebook-jssdk'));
|
|
29
|
-
initFacebookSdk();
|
|
30
|
-
}, [facebookAppId]);
|
|
31
|
-
const initFacebookSdk = () => {
|
|
32
|
-
window.fbAsyncInit = () => {
|
|
33
|
-
window.FB.init({
|
|
34
|
-
appId: facebookAppId,
|
|
35
|
-
cookie: true,
|
|
36
|
-
xfbml: true,
|
|
37
|
-
version: 'v16.0'
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
const loginWithFacebook = () => {
|
|
42
|
-
if (!window.FB) {
|
|
43
|
-
showMessage({
|
|
44
|
-
message: "Facebook login is still initialising. Please try again in a moment.",
|
|
45
|
-
type: "warning",
|
|
46
|
-
});
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
window.FB.login(() => checkLoginState(), {
|
|
50
|
-
scope: "public_profile,email",
|
|
51
|
-
return_scopes: true,
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
const checkLoginState = () => window.FB.getLoginStatus((response) => {
|
|
55
|
-
statusChangeCallback(response);
|
|
56
|
-
});
|
|
57
|
-
// ✅ Handle status
|
|
58
|
-
const statusChangeCallback = useCallback(async (response) => {
|
|
59
|
-
try {
|
|
60
|
-
if (response.status === "connected") {
|
|
61
|
-
const accessToken = response.authResponse.accessToken;
|
|
62
|
-
window.FB.api("/me", { fields: "name,email" }, async (userResponse) => {
|
|
63
|
-
const { email, name, id: fbUserId } = userResponse;
|
|
64
|
-
if (!email) {
|
|
65
|
-
facebookSignOut();
|
|
66
|
-
showMessage({
|
|
67
|
-
message: "We couldn’t retrieve your Facebook email. Please use another login method or update your Facebook permissions.",
|
|
68
|
-
type: "error",
|
|
69
|
-
});
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const nameParts = name.split(" ");
|
|
73
|
-
//{ error, isValid, loginType } = await verifyLoginType(email, LoginMethodCode.Facebook);
|
|
74
|
-
const result = await handleFacebookAuth({
|
|
75
|
-
email,
|
|
76
|
-
facebookIdentityToken: accessToken,
|
|
77
|
-
platform: "web",
|
|
78
|
-
});
|
|
79
|
-
switch (result.status) {
|
|
80
|
-
case "REGISTER":
|
|
81
|
-
onRegistrationMethodChange(RegistrationMethod.SOCIAL);
|
|
82
|
-
return navigator.pushAbsolute("/registration", {
|
|
83
|
-
query: {
|
|
84
|
-
email,
|
|
85
|
-
firstName: nameParts[0],
|
|
86
|
-
lastName: nameParts[1] || "",
|
|
87
|
-
fbUserId,
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
case "INVALID":
|
|
91
|
-
facebookSignOut();
|
|
92
|
-
return showMessage({
|
|
93
|
-
message: `You have previously registered using your ${result.data.existingLoginType}. Please use your ${result.data.existingLoginType} to login method.`,
|
|
94
|
-
type: "error",
|
|
95
|
-
});
|
|
96
|
-
case "SUCCESS":
|
|
97
|
-
onTokenChange(result.data.token);
|
|
98
|
-
onLogin({ token: result.data.token, member: result.data.member });
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
console.log("Google login failed:", error);
|
|
106
|
-
setError(error);
|
|
107
|
-
return { error };
|
|
108
|
-
}
|
|
109
|
-
}, []);
|
|
110
|
-
// ✅ Logout
|
|
111
|
-
const facebookSignOut = useCallback(() => {
|
|
112
|
-
window.FB.api("/me/permissions", "delete", null, () => window.FB.logout((res) => statusChangeCallback(res)));
|
|
113
|
-
}, [statusChangeCallback]);
|
|
114
|
-
return { loginWithFacebook, facebookSignOut, error };
|
|
115
|
-
};
|