Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3504189
D11766.id39557.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D11766.id39557.diff
View Options
diff --git a/lib/hooks/login-hooks.js b/lib/hooks/login-hooks.js
--- a/lib/hooks/login-hooks.js
+++ b/lib/hooks/login-hooks.js
@@ -27,28 +27,14 @@
const inactiveStep = { step: 'inactive' };
-type UsePasswordLogInInput = {
- // Called after successful identity auth, but before successful authoritative
- // keyserver auth. Used by callers to trigger local persistence of credentials
- +saveCredentials?: ?({ +username: string, +password: string }) => mixed,
-};
-function usePasswordLogIn(
- input?: ?UsePasswordLogInInput,
-): (username: string, password: string) => Promise<void> {
+function usePasswordLogIn(): (
+ username: string,
+ password: string,
+) => Promise<void> {
const [currentStep, setCurrentStep] =
React.useState<CurrentStep>(inactiveStep);
- const saveCredentials = input?.saveCredentials;
const identityPasswordLogIn = useIdentityPasswordLogIn();
- const identityLogInAction = React.useCallback(
- async (username: string, password: string) => {
- const result = await identityPasswordLogIn(username, password);
- saveCredentials?.({ username, password });
- return result;
- },
- [identityPasswordLogIn, saveCredentials],
- );
-
const dispatchActionPromise = useDispatchActionPromise();
const returnedFunc = React.useCallback(
(username: string, password: string) =>
@@ -58,7 +44,7 @@
if (currentStep.step !== 'inactive') {
return;
}
- const action = identityLogInAction(username, password);
+ const action = identityPasswordLogIn(username, password);
void dispatchActionPromise(identityLogInActionTypes, action);
try {
await action;
@@ -72,7 +58,7 @@
}
},
),
- [currentStep, dispatchActionPromise, identityLogInAction],
+ [currentStep, dispatchActionPromise, identityPasswordLogIn],
);
const keyserverAuth = useKeyserverAuth(authoritativeKeyserverID());
diff --git a/native/account/log-in-panel.react.js b/native/account/log-in-panel.react.js
--- a/native/account/log-in-panel.react.js
+++ b/native/account/log-in-panel.react.js
@@ -330,6 +330,10 @@
this.passwordInputText,
);
this.props.setActiveAlert(false);
+ await setNativeCredentials({
+ username: this.usernameInputText,
+ password: this.passwordInputText,
+ });
} catch (e) {
const messageForException = getMessageForException(e);
if (
@@ -435,7 +439,6 @@
);
const olmSessionInitializationDataLoadingStatusSelector =
createLoadingStatusSelector(getOlmSessionInitializationDataActionTypes);
-const identityPasswordLogInInput = { saveCredentials: setNativeCredentials };
const ConnectedLogInPanel: React.ComponentType<BaseProps> =
React.memo<BaseProps>(function ConnectedLogInPanel(props: BaseProps) {
@@ -452,9 +455,7 @@
const dispatchActionPromise = useDispatchActionPromise();
const callLegacyLogIn = useLegacyLogIn();
- const callIdentityPasswordLogIn = usePasswordLogIn(
- identityPasswordLogInInput,
- );
+ const callIdentityPasswordLogIn = usePasswordLogIn();
const getInitialNotificationsEncryptedMessage =
useInitialNotificationsEncryptedMessage(authoritativeKeyserverID);
diff --git a/native/account/registration/registration-server-call.js b/native/account/registration/registration-server-call.js
--- a/native/account/registration/registration-server-call.js
+++ b/native/account/registration/registration-server-call.js
@@ -65,6 +65,7 @@
+step: 'identity_registration_dispatched',
+clearCachedSelections: () => void,
+avatarData: ?AvatarData,
+ +credentialsToSave: ?{ +username: string, +password: string },
+resolve: () => void,
+reject: Error => void,
}
@@ -72,6 +73,7 @@
+step: 'authoritative_keyserver_registration_dispatched',
+clearCachedSelections: () => void,
+avatarData: ?AvatarData,
+ +credentialsToSave: ?{ +username: string, +password: string },
+resolve: () => void,
+reject: Error => void,
};
@@ -97,16 +99,11 @@
) => {
const identityRegisterPromise = (async () => {
try {
- const result = await callIdentityPasswordRegister(
+ return await callIdentityPasswordRegister(
accountSelection.username,
accountSelection.password,
farcasterID,
);
- await setNativeCredentials({
- username: accountSelection.username,
- password: accountSelection.password,
- });
- return result;
} catch (e) {
if (e.message === 'username reserved') {
Alert.alert(
@@ -149,7 +146,7 @@
const extraInfo = await logInExtraInfo();
const keyserverRegisterPromise = (async () => {
try {
- const result = await callKeyserverRegister(
+ return await callKeyserverRegister(
{
...extraInfo,
username: accountSelection.username,
@@ -159,11 +156,6 @@
urlPrefixOverride: keyserverURL,
},
);
- await setNativeCredentials({
- username: result.currentUserInfo.username,
- password: accountSelection.password,
- });
- return result;
} catch (e) {
if (e.message === 'username_reserved') {
Alert.alert(
@@ -277,10 +269,18 @@
if (siweBackupSecrets) {
await commCoreModule.setSIWEBackupSecrets(siweBackupSecrets);
}
+ const credentialsToSave =
+ accountSelection.accountType === 'username'
+ ? {
+ username: accountSelection.username,
+ password: accountSelection.password,
+ }
+ : null;
setCurrentStep({
step: 'identity_registration_dispatched',
avatarData,
clearCachedSelections,
+ credentialsToSave,
resolve,
reject,
});
@@ -320,7 +320,13 @@
return;
}
registeringOnAuthoritativeKeyserverRef.current = true;
- const { avatarData, clearCachedSelections, resolve, reject } = currentStep;
+ const {
+ avatarData,
+ clearCachedSelections,
+ credentialsToSave,
+ resolve,
+ reject,
+ } = currentStep;
void (async () => {
try {
await keyserverAuth({
@@ -335,6 +341,7 @@
step: 'authoritative_keyserver_registration_dispatched',
avatarData,
clearCachedSelections,
+ credentialsToSave,
resolve,
reject,
});
@@ -366,7 +373,8 @@
return;
}
avatarBeingSetRef.current = true;
- const { avatarData, resolve, clearCachedSelections } = currentStep;
+ const { avatarData, resolve, clearCachedSelections, credentialsToSave } =
+ currentStep;
void (async () => {
try {
if (!avatarData) {
@@ -391,6 +399,9 @@
},
});
clearCachedSelections();
+ if (credentialsToSave) {
+ void setNativeCredentials(credentialsToSave);
+ }
setCurrentStep(inactiveStep);
avatarBeingSetRef.current = false;
resolve();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 7:36 AM (18 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2684481
Default Alt Text
D11766.id39557.diff (7 KB)
Attached To
Mode
D11766: [lib][native] Defer saving user credentials until successful auth
Attached
Detach File
Event Timeline
Log In to Comment