Page MenuHomePhabricator

[native] try to log in if native user is missing CSAT
ClosedPublic

Authored by varun on May 20 2024, 7:52 AM.
Tags
None
Referenced Files
F3351694: D12128.diff
Sat, Nov 23, 3:14 AM
Unknown Object (File)
Mon, Nov 18, 4:55 AM
Unknown Object (File)
Fri, Nov 8, 10:35 PM
Unknown Object (File)
Fri, Nov 8, 1:26 PM
Unknown Object (File)
Fri, Nov 8, 12:25 PM
Unknown Object (File)
Fri, Nov 8, 12:25 PM
Unknown Object (File)
Fri, Nov 8, 12:25 PM
Unknown Object (File)
Fri, Nov 8, 12:25 PM
Subscribers
None

Details

Summary

if a native password user is missing a CSAT (and usingCommServicesAccessToken is true), we should try to log in the identity and get a new CSAT

Test Plan

using this patch, i cleared the access token on native and confirmed that i was logged in to identity again and received a new access token. i confirmed that if identity is unavailable, i get logged out and the alert displays explaining why i was logged out.

also confirmed that my avatar doesn't get removed, since we perform keyserver auth as part of the usePasswordLogIn hook

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

varun requested review of this revision.May 20 2024, 8:10 AM
ashoat requested changes to this revision.Jun 1 2024, 12:19 PM

Not sure about not dispatching a Redux action here. See inline comment

native/components/background-identity-login-handler.react.js
38–53

Same comment as in D11912: you should exit early and reduce indentation

By keeping multiple branches open when you could quickly close one instead, you're forcing the reader to have to spend more "mental RAM" trying to understand your code

41

This is an unexpected case, right? Can we add a console.log here?

44–47

You don't seem to be dispatching the action, and my first thought was that you should be doing this here.

But looking at the reducers, there are only three places where this action is reduced:

  1. In nav-reducer.js and keyserver-reducer.js, it would only matters if the userID from the action doesn't match the one currently in Redux
  2. In reduceCurrentUserInfo, it will actually strip the avatar (and the as-of-yet-unused settings) from the CurrentUserInfo, which is not good.

I think it's kind of weird not to dispatch an action here. It makes eg. our error reports worse, and a bit hard for developers to track what's going on while testing.

But if we were to dispatch the action here linked in the code I linked at the start of this comment, then we would also need to fix up reduceCurrentUserInfo to do a merge, similar to how it currently handles setNewSessionActionType here.

What do you think?

This revision now requires changes to proceed.Jun 1 2024, 12:19 PM
native/components/background-identity-login-handler.react.js
44–47

By the way, the reason it works without a dispatch here is that the SET_ACCESS_TOKEN action is dispatched separately via the CommServicesAuthMetadataEmitter

native/components/background-identity-login-handler.react.js
44–47

I'm actually using the function you linked in the first line of your comment. It handles dispatching the action

native/components/background-identity-login-handler.react.js
48 ↗(On Diff #40890)

realized we should probably log out and alert here, too

Talked to @varun offline about the Redux dispatch. I definitely misread this on first glance, and thought it was using useIdentityPasswordLogIn instead of usePasswordLogIn.

I asked him why we were doing keyserver auth as well, instead of just identity auth. He explained that we need the keyserver auth to make sure that the content Olm session is set up.

Note that my concerns about reduceCurrentUserInfo don't apply when using useIdentityPasswordLogIn. While it's true that the identity auth will clear the avatar, the subsequent authoritative keyserver auth should repopulate it. If the authoritative keyserver auth fails for some reason, the user will be logged out.

This revision is now accepted and ready to land.Jun 3 2024, 12:08 PM
native/components/background-identity-login-handler.react.js
48 ↗(On Diff #40890)

Good call