Closed TheNoodleMoose closed 2 years ago
My initial thoughts:
if not x endpoint
for handling logic like this (these lists tend to be always growing)crsToken
is expired?crsToken
on 401
response, how easy is it to get a new one that is not expired?401
comes back?@wrandall22 Thanks for looking at this and providing feedback! I'll try to go ahead and reply back to each point you made.
crsToken
exists(regardless of being expired), it just displays the login modal. So on every page load, it's requesting the data for that page, and the profile data. So if both requests require a valid token, both will get a 401 and two modals will popup. Maybe we can delete the crsToken
if it runs into a 401 the first time. But I'm not sure if that has any effects on other logic that is in place. There are several places where regardless of logged-in status, we are requesting the profile data(I believe it's related to analytics). I could investigate cleaning that up, but not sure how long/how much effort that will take to do so. I guess the part that seems to need to be smarter is this:
So on every page load, it's requesting the data for that page, and the profile data.
The profile page should be smart enough to know that the data for that page = the profile data.
@wrandall22 There's actually no profile page, it's just an endpoint that holds user profile data that is updated based on their answers to questions like address, name, email, etc. The front end, however, only requests this data. All updating happens on the API side. But we seem to be requesting that profile data on every page load, route change, etc.
There's actually logic that will not fetch the profile data if there is no crsToken
, but that token does not get deleted on a 401
, so the request happens: https://github.com/CruGlobal/conf-registration-web/blob/36f56a001b35b14965eec6a2dcc7857713586864/app/scripts/services/ProfileCache.js#L23
Ah, I see. I guess this is where GraphQL could help. One request that gets page data + profile data. Otherwise it would be slowing down the page by requesting them sequentially. Probably lots of ways it could go to be a good solution.
The API recently updated so that the
/profile
endpoint correctly returns a401
instead of a503
. However, this has led to a double modal being presented to the user, that persists even after they finish signing in. TheunauthorizedInterceptor
just checks to see if the request status was a401
and if the user currently has acrsToken
cookie(which most likely has expired). If so, show the modal. So when the user's token expired, they get presented a modal for the first request that was unauthorized, and then a second modal for the profile data request. I figured we don't necessarily need to have them sign in to get their profile data, as even if they were on the landing page(a page that does not require auth), the modal would pop up. Maybe this would be resolved if we removed thecrsToken
if we hit a401
error(i.e always delete the crsToken if 401, but only show modal if the request was not for profile data)? Let me know what you think!