Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3352220
D12128.id40890.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D12128.id40890.diff
View Options
diff --git a/native/components/background-identity-login-handler.react.js b/native/components/background-identity-login-handler.react.js
--- a/native/components/background-identity-login-handler.react.js
+++ b/native/components/background-identity-login-handler.react.js
@@ -3,13 +3,14 @@
import * as React from 'react';
import { logOutActionTypes, useLogOut } from 'lib/actions/user-actions.js';
-import { useModalContext } from 'lib/components/modal-provider.react.js';
+import { usePasswordLogIn } from 'lib/hooks/login-hooks.js';
import { accountHasPassword } from 'lib/shared/account-utils.js';
import { securityUpdateLogoutText } from 'lib/types/alert-types.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
import { useSelector } from 'lib/utils/redux-utils.js';
import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js';
+import { fetchNativeKeychainCredentials } from '../account/native-credentials.js';
import Alert from '../utils/alert.js';
function BackgroundIdentityLoginHandler() {
@@ -22,26 +23,51 @@
const hasAccessToken = useSelector(state => !!state.commServicesAccessToken);
const dataLoaded = useSelector(state => state.dataLoaded);
- const { pushModal } = useModalContext();
+ const callIdentityPasswordLogIn = usePasswordLogIn();
- React.useEffect(() => {
+ const handleLogOutAndAlert = React.useCallback(() => {
+ void dispatchActionPromise(logOutActionTypes, callLogOut());
+ Alert.alert('Security update', securityUpdateLogoutText, [{ text: 'OK' }]);
+ }, [dispatchActionPromise, callLogOut]);
+
+ const logInIfPossibleElseLogOut = React.useCallback(async () => {
if (hasAccessToken || !dataLoaded || !usingCommServicesAccessToken) {
return;
}
+
if (!isAccountWithPassword) {
- void dispatchActionPromise(logOutActionTypes, callLogOut());
- Alert.alert('Security update', securityUpdateLogoutText, [
- { text: 'OK' },
- ]);
+ handleLogOutAndAlert();
+ return;
+ }
+
+ const nativeCredentials = await fetchNativeKeychainCredentials();
+ if (!nativeCredentials) {
+ console.log(
+ 'Native credentials missing. Cannot log in to identity service',
+ );
+ handleLogOutAndAlert();
+ return;
+ }
+
+ try {
+ await callIdentityPasswordLogIn(
+ nativeCredentials.username,
+ nativeCredentials.password,
+ );
+ } catch (e) {
+ handleLogOutAndAlert();
}
}, [
- callLogOut,
+ callIdentityPasswordLogIn,
dataLoaded,
- dispatchActionPromise,
+ handleLogOutAndAlert,
hasAccessToken,
isAccountWithPassword,
- pushModal,
]);
+
+ React.useEffect(() => {
+ void logInIfPossibleElseLogOut();
+ }, [logInIfPossibleElseLogOut]);
}
export default BackgroundIdentityLoginHandler;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 5:07 AM (21 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573655
Default Alt Text
D12128.id40890.diff (2 KB)
Attached To
Mode
D12128: [native] try to log in if native user is missing CSAT
Attached
Detach File
Event Timeline
Log In to Comment