@truworth/twc-auth 3.0.13 → 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/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/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
|
}
|
|
@@ -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:
|
|
@@ -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
|
-
};
|