Skip to content
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

check currentUser with accountID #29090

Merged
merged 7 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/pages/DetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ const propTypes = {
/** Route params */
route: matchType.isRequired,

/** Login list for the user that is signed in */
loginList: PropTypes.shape({
/** Date login was validated, used to show info indicator status */
validatedDate: PropTypes.string,

/** Field-specific server side errors keyed by microtime */
errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)),
/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user email */
email: PropTypes.string,
}),

...withLocalizePropTypes,
Expand All @@ -63,7 +60,9 @@ const propTypes = {
const defaultProps = {
// When opening someone else's profile (via deep link) before login, this is empty
personalDetails: {},
loginList: {},
session: {
email: '',
},
};

/**
Expand Down Expand Up @@ -123,7 +122,7 @@ function DetailsPage(props) {
const phoneNumber = getPhoneNumber(details);
const phoneOrEmail = isSMSLogin ? getPhoneNumber(details) : details.login;

const isCurrentUser = _.keys(props.loginList).includes(details.login);
const isCurrentUser = props.session.email === login.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the account id.

Copy link
Contributor Author

@c3024 c3024 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we can get accountID here only by checking corresponding login in personal details. Here we get only login from URL.

When we login with deeplink, personal details are not loaded immediately so account id is undefined and the check returns false even for same current user and the message button appears briefly.

Not related to this discussion but I made a mistake with the commit name for details Page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm in that case please revert. We can't compare with session.email because one account can have multiple emails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I missed that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or wait, currently we are comparing details.login from onyx and not login from route params. So if we just use details.accountID then we won't be introducing a new change (in terms of deep link behavior)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea but that does not help in fixing this bug either.
If we get directly from URL then we can get the current user check instantly. But like you said, the primary login may be different so session.email === email from url does not work.
Changing to accountID also has no use in this case. Loginlist and personaldetails are loaded more or less at the same time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the change to DetailsPage will fix nothing. but also will break nothing right? I'm suggesting this just for consistency i.e. to have the isCurrentUser always related to the account id

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I will make that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


return (
<ScreenWrapper testID={DetailsPage.displayName}>
Expand Down Expand Up @@ -225,8 +224,8 @@ export default compose(
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
loginList: {
key: ONYXKEYS.LOGIN_LIST,
session: {
key: ONYXKEYS.SESSION,
},
}),
)(DetailsPage);
24 changes: 13 additions & 11 deletions src/pages/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,25 @@ const propTypes = {
/** Route params */
route: matchType.isRequired,

/** Login list for the user that is signed in */
loginList: PropTypes.shape({
/** Phone/Email associated with user */
partnerUserID: PropTypes.string,
}),

/** Indicates whether the app is loading initial data */
isLoadingReportData: PropTypes.bool,

/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user accountID */
accountID: PropTypes.number,
}),

...withLocalizePropTypes,
};

const defaultProps = {
// When opening someone else's profile (via deep link) before login, this is empty
personalDetails: {},
loginList: {},
isLoadingReportData: true,
session: {
accountID: 0,
},
};

/**
Expand Down Expand Up @@ -121,7 +123,7 @@ function ProfilePage(props) {
const phoneNumber = getPhoneNumber(details);
const phoneOrEmail = isSMSLogin ? getPhoneNumber(details) : login;

const isCurrentUser = _.keys(props.loginList).includes(login);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If loginList is not used anywhere remove it from onyx subscription

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done.

const isCurrentUser = props.session.accountID === accountID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this same fix for <DetailsPage />

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done but the route param is email so the comparison is done with session.email.

const hasMinimumDetails = !_.isEmpty(details.avatar) && !_.isUndefined(details.displayName);
const isLoading = lodashGet(details, 'isLoading', false) || _.isEmpty(details) || props.isLoadingReportData;

Expand Down Expand Up @@ -280,12 +282,12 @@ export default compose(
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
loginList: {
key: ONYXKEYS.LOGIN_LIST,
},
isLoadingReportData: {
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
},
session: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add session to props

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Done. Apologies for missing basic things in haste.

key: ONYXKEYS.SESSION,
},
betas: {
key: ONYXKEYS.BETAS,
},
Expand Down
Loading