-
Notifications
You must be signed in to change notification settings - Fork 1
feat(oauth): restore update flow and handle new inbound members #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
030f253
ea2e70b
642da17
b7095dc
614f063
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,5 @@ dist-ssr | |
| *.sln | ||
| *.sw? | ||
| .tool-versions | ||
|
|
||
| tmp | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import React, { useEffect, useState, useRef, useImperativeHandle, useContext } f | |
| import PropTypes from 'prop-types' | ||
| import { useSelector, useDispatch } from 'react-redux' | ||
| import { defer, of } from 'rxjs' | ||
| import { mergeMap, map, pluck } from 'rxjs/operators' | ||
| import { mergeMap, map } from 'rxjs/operators' | ||
|
|
||
| import { useApi } from 'src/context/ApiContext' | ||
| import { ReadableStatuses } from 'src/const/Statuses' | ||
|
|
@@ -123,22 +123,19 @@ export const OAuthStep = React.forwardRef((props, navigationRef) => { | |
| let member$ | ||
|
|
||
| /** | ||
| * WARNING: don't change this area without data to back up your changes | ||
| * NOTE: We are re-enabling the use of existing member GUIDs for OAuth flows (Update flow). | ||
| * | ||
| * There has been a flip-flop of problems in this area, so this note is being written as a warning. | ||
| * Using existing OAuth members causes problems, because if a new set of credentials is used for | ||
| * an existing member, our system ends up in a bad state, where the old member gets mangled up with | ||
| * the new credentials. | ||
| * Historically, this caused "member combination" issues. We now mitigate this by | ||
| * detecting if the backend returns a different inbound_member_guid in WaitingForOAuth.js. | ||
| * If a change is detected, we fetch the new member record and update the Redux state | ||
| * accordingly, ensuring session integrity even if the GUID migrates during the flow. | ||
| * | ||
| * We tried to reduce the amount of members created by re-using existing oauth members, but that caused | ||
| * a regression of a client reported bug, so we had to move this back to always creating new members, | ||
| * or using existing pending oauth members. | ||
| * | ||
| * Previous code attempt that was used to reduce member creation, but reintroduced the bug: | ||
| * if (member && member.is_oauth && api.getOAuthWindowURI) { | ||
| * member$ = of(member) | ||
| * The backend will ultimately decide when to send us back the same member guid, or a new one | ||
| */ | ||
| if (pendingOauthMember) { | ||
| if (member?.is_oauth && api.getOAuthWindowURI) { | ||
| // If there is an existing member, don't create a new one, use that one (restores update flow) | ||
| member$ = of(member) | ||
| } else if (pendingOauthMember) { | ||
| // If there is a pending oauth member, don't create a new one, use that one | ||
| member$ = of(pendingOauthMember) | ||
| } else { | ||
|
|
@@ -155,7 +152,7 @@ export const OAuthStep = React.forwardRef((props, navigationRef) => { | |
| config, | ||
| ), | ||
| ) | ||
| .pipe(pluck('member')) | ||
| .pipe(map((resp) => resp.member)) | ||
| .subscribe( | ||
| (member) => { | ||
| sendAnalyticsEvent(AnalyticEvents.OAUTH_PENDING_MEMBER_CREATED, { | ||
|
|
@@ -216,9 +213,14 @@ export const OAuthStep = React.forwardRef((props, navigationRef) => { | |
| setIsWaitingForOAuth(false) | ||
| } | ||
|
|
||
| function handleOAuthSuccess(memberGuid) { | ||
| function handleOAuthSuccess(memberGuid, member = null) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be clearer if we explicitly distinguished between the inbound member and the original member here. Better naming would make the flow easier to follow and maintain for future devs.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The memberGuid and the member are always going to be related to each other. If
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so does that mean we can’t tell which one is which at this point?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I can see in the code, |
||
| closeOAuthWindow() | ||
| dispatch(connectActions.handleOAuthSuccess(memberGuid)) | ||
|
|
||
| if (member) { | ||
| dispatch(connectActions.updateMemberSuccess(member)) | ||
| } else { | ||
| dispatch(connectActions.handleOAuthSuccess(memberGuid)) | ||
| } | ||
| } | ||
|
|
||
| function handleOAuthError(memberGuid, errorReason = null) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.