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

Fix visibleGroups is undefined error #77

Merged
merged 1 commit into from
Jan 13, 2020

Conversation

kairstenfay
Copy link
Contributor

In further testing of #74, we found an error when a user is logged-out
that prevented the splash page of nextstrain.org from loading.

Fix the error by checking if visibleGroups is defined in addition to
user before rendering the <UserGroups> component.

@kairstenfay kairstenfay requested a review from tsibley January 10, 2020 19:29
@tsibley tsibley temporarily deployed to nextstrain-s-fix-visibl-r6gdap January 10, 2020 19:29 Inactive
@@ -52,7 +52,7 @@ class Splash extends React.Component {

<HugeSpacer/>

{this.props.user && <UserGroups user={this.props.user}/>}
{this.props.user && this.props.user.visibleGroups && <UserGroups user={this.props.user}/>}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a little confused here how/why this.props.user was defined when there was no logged-in user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

user is getting passed to the Splash component via the UserDataWrapper component, which by default is undefined.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, so looking closer, what's happening is that I have an existing login session (like most of our users will) but it lacks the visibleGroups attribute because that's only added by your previous PR. In order to get the new attribute with the current code, a person has to logout and log back in again. We can either guard against the missing attribute everywhere (a little ugly), or could put the computation somewhere else so it happens every time, not only in the login flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, right. @jameshadfield initially pointed that out as a consequence of moving the visibleGroups logic inside the setup of OAuth2Strategy.

I now recall that was the error I encountered in testing and fixed by logging in and out again.

Copy link
Contributor Author

@kairstenfay kairstenfay Jan 10, 2020

Choose a reason for hiding this comment

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

Is there no third solution where, now that the splash page is no longer broken, we can tell logged-in users to log in and out again? 😄

edit: I realize now that we will not want to make users log in and out every time they get added to a new group. So this is not a real solution.

Copy link
Member

Choose a reason for hiding this comment

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

edit: I realize now that we will not want to make users log in and out every time they get added to a new group. So this is not a real solution.

The Cognito groups for a user are (as I understand the code) only fetched when a user logs in, so I don't think it's possible (as currently implemented) to see a new cognito group without logging in again

Copy link
Member

Choose a reason for hiding this comment

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

The Cognito groups for a user are (as I understand the code) only fetched when a user logs in, so I don't think it's possible (as currently implemented) to see a new cognito group without logging in again

Correct. We can improve this in the future by refreshing user details from Cognito on ~every request (or, ideally, with some short-lived cache).

Copy link
Member

@tsibley tsibley left a comment

Choose a reason for hiding this comment

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

I describe the issue a bit more in my reply to your comment.

Separately, the /users/trs page is also broken for me when I have an existing login session.

@@ -52,7 +52,7 @@ class Splash extends React.Component {

<HugeSpacer/>

{this.props.user && <UserGroups user={this.props.user}/>}
{this.props.user && this.props.user.visibleGroups && <UserGroups user={this.props.user}/>}
Copy link
Member

Choose a reason for hiding this comment

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

Ah, so looking closer, what's happening is that I have an existing login session (like most of our users will) but it lacks the visibleGroups attribute because that's only added by your previous PR. In order to get the new attribute with the current code, a person has to logout and log back in again. We can either guard against the missing attribute everywhere (a little ugly), or could put the computation somewhere else so it happens every time, not only in the login flow.

@kairstenfay kairstenfay force-pushed the Fix-visibleGroups-undefined-error branch from e8169d2 to aae1c22 Compare January 10, 2020 23:22
@tsibley tsibley temporarily deployed to nextstrain-s-fix-visibl-r6gdap January 10, 2020 23:23 Inactive
@kairstenfay kairstenfay force-pushed the Fix-visibleGroups-undefined-error branch from aae1c22 to 393cae0 Compare January 10, 2020 23:29
@tsibley tsibley temporarily deployed to nextstrain-s-fix-visibl-r6gdap January 10, 2020 23:29 Inactive
@kairstenfay
Copy link
Contributor Author

I moved the logic for determining visibleGroups back to its original place in authn.js under the /whoami endpoint.

@kairstenfay kairstenfay force-pushed the Fix-visibleGroups-undefined-error branch from 393cae0 to 33b9d60 Compare January 10, 2020 23:31
@tsibley tsibley temporarily deployed to nextstrain-s-fix-visibl-r6gdap January 10, 2020 23:31 Inactive
@kairstenfay
Copy link
Contributor Author

kairstenfay commented Jan 10, 2020

I'm still getting a console error when logged out:

TypeError: Cannot read property 'groups' of undefined
    at Object.json (/home/kairsten/nextstrain/nextstrain.org/authn.js:229:33)
    at ServerResponse.res.format (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/response.js:675:13)
    at app.route.get (/home/kairsten/nextstrain/nextstrain.org/authn.js:220:16)
    at Layer.handle [as handle_request] (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/layer.js:95:5)
    at /home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/index.js:335:12)
    at next (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/index.js:275:10)
TypeError: Cannot read property 'groups' of undefined
    at Object.json (/home/kairsten/nextstrain/nextstrain.org/authn.js:229:33)
    at ServerResponse.res.format (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/response.js:675:13)
    at app.route.get (/home/kairsten/nextstrain/nextstrain.org/authn.js:220:16)
    at Layer.handle [as handle_request] (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/layer.js:95:5)
    at /home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/index.js:335:12)
    at next (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/index.js:275:10)
TypeError: Cannot read property 'groups' of undefined
    at Object.json (/home/kairsten/nextstrain/nextstrain.org/authn.js:229:33)
    at ServerResponse.res.format (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/response.js:675:13)
    at app.route.get (/home/kairsten/nextstrain/nextstrain.org/authn.js:220:16)
    at Layer.handle [as handle_request] (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/layer.js:95:5)
    at /home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/index.js:335:12)
    at next (/home/kairsten/nextstrain/nextstrain.org/node_modules/express/lib/router/index.js:275:10)

I'm currently still investigating a working solution.

edit: fixed

In further testing of #74, we found an error when a user is logged-out
that prevented the splash page of nextstrain.org from loading.

Move the logic for determining which groups are visible to a user into
the `/whoami` endpoint. Send the resulting `visibleGroups` as an
additional key in the json load sent by this endpoint. Handle the
additional `visibleGroups` object accordingly.
@kairstenfay kairstenfay force-pushed the Fix-visibleGroups-undefined-error branch from 33b9d60 to 2d1f3b6 Compare January 11, 2020 01:09
@tsibley tsibley temporarily deployed to nextstrain-s-fix-visibl-r6gdap January 11, 2020 01:09 Inactive
@tsibley tsibley merged commit 2d1f3b6 into master Jan 13, 2020
@tsibley
Copy link
Member

tsibley commented Jan 13, 2020

Thanks for fixing this, @kairstenfay. Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants