libscie / ResearchEquals.com

Research module server
https://researchequals.com
MIT License
88 stars 10 forks source link

Fixing the 400 error on dashboard page #2103

Closed nsunami closed 4 months ago

nsunami commented 4 months ago

This is my attempt to fix the 400 error on the dashboard page. As reported in #2101, the dashboard page was throwing a 400 error. The error message varied from d is null to Cannot read properties of null (reading "firstName").

When looking at the Dashboard page, I noticed that the workspace information is expected to be non-null, by non-null assertion by bang (!):

{currentWorkspace!.firstName && currentWorkspace!.lastName
? `${currentWorkspace!.firstName} ${currentWorkspace!.lastName}`
: `@${currentWorkspace!.handle}`}

I assume this means that when the currentWorkspace object is indeed null (when logging out), it will throw an error. I changed this part of the code to allow nullish values:

{currentWorkspace?.firstName && currentWorkspace?.lastName
? `${currentWorkspace.firstName} ${currentWorkspace.lastName}`
: `@${currentWorkspace?.handle}`}

Other line changes are due to code formatting.

@chartgerink : Could you check logging in and out several times to see if you get a 400 error on your side?

nsunami commented 4 months ago

Update: Now I get

Unhandled Runtime Error
TypeError: Cannot read properties of null (reading 'supporting')
image

I suspect that the redirect may not be working well.

I wonder if we can regard this Onboarding quest issue as a different issue or not.

chartgerink commented 4 months ago

Ah yes - thanks for trying to fix this 🙏

The currentUser is indeed potentially not available when people directly go to the /dashboard route (previously d is null or similar). What we could do, is wrap the OnboardingQuests in a conditional render only when currentUser is not null. This would be in addition to your already proposed changes.

It would look something like this:


return (
  <>{currentUser && 
    <>
      <OnboardingQuest1 />
    </>}
  </>
)

I suspect this will fix both our problems, but I would encourage a bit of testing and trying to break it 😊

github-actions[bot] commented 4 months ago

This pull request is stale because it has been open for 2 days with no activity.

nsunami commented 4 months ago

@chartgerink thanks! I adopted your suggestion. I tried logging in and out while on /dashboard multiple times, and I no longer get an error.

Could you check?

github-actions[bot] commented 4 months ago

This pull request is stale because it has been open for 2 days with no activity.

chartgerink commented 4 months ago

@nsunami thanks for the updates and patience - I was out on vacation 🌴

I think this is sufficient for now - I do get a bit of a flashy screen that I would personally consider problematic for production in general. 👇 (it's worse than this at times)

https://github.com/user-attachments/assets/e4eb5639-1049-4f70-a6b3-97fa5d309349

However, given that we are working towards a v2 and this is such a specific case, I think this is acceptable in the scenario of keeping the current version functional until v2 launches.