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
Unknown Object (File)
Fri, Jun 21, 4:57 AM
Unknown Object (File)
Fri, Jun 21, 4:57 AM
Unknown Object (File)
Fri, Jun 21, 4:57 AM
Unknown Object (File)
Tue, Jun 18, 9:37 PM
Unknown Object (File)
Tue, Jun 18, 3:19 PM
Unknown Object (File)
Sat, Jun 15, 8:45 AM
Unknown Object (File)
Fri, Jun 14, 4:41 PM
Unknown Object (File)
Fri, Jun 14, 2:17 AM
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
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

varun requested review of this revision.May 20 2024, 8:10 AM
ashoat requested changes to this revision.Sat, Jun 1, 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 ↗(On Diff #40814)

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 ↗(On Diff #40814)

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

44–47 ↗(On Diff #40814)

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.Sat, Jun 1, 12:19 PM
native/components/background-identity-login-handler.react.js
44–47 ↗(On Diff #40814)

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 ↗(On Diff #40814)

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.Mon, Jun 3, 12:08 PM
native/components/background-identity-login-handler.react.js
48 ↗(On Diff #40890)

Good call