Search code examples
javascriptreactjssingle-page-applicationstormpathexpress-stormpath

express-stormpath w/ react-stormpath: this.context.user doesn't reflect groups the user has recently been added to


Using the express and react Stormpath libraries, I have a fairly unique use-case:

Upon a successful Sign Up the user is automatically logged-in and asked a few questions. Depending on the answers the user gives, the user is then programatically added to specific Stormpath Groups. After this questioning period I then route the user to a Profile page where they can edit some profile data, etc. I need to know which groups the user is in, in order to render the correct Profile elements etc.

I think the easiest way to commonly do this is just to use this.context.user to determine which groups the currently logged-in user is a part of. However, I notice that even after the user has successfully been added to these various groups, whenever I inspect this.context.user I notice that it does not reflect the groups they have just recently been added to. In order to get this.context.user to reflect the recently added groups, I need to do a full page refresh which in turn 'refreshes' this.context.user.

I am wondering if there is a way to 'refresh' this.context.user. I would prefer a solution that does not refresh the page, and I would also prefer having not to call a server-side endpoint to determine which groups the user is in.


Solution

  • A GET to the /me endpoint is the best way to "refresh" the user information.

    also be aware that Stormpath has joined Okta and that the API will go offline at noon on 8/17/2017