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

Use getSession's status within auth and account layouts to render/re-direct #30

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

madhurjain
Copy link
Contributor

If we visit the settings page https://demo.nextacular.co/account/settings and hit refresh/reload, we end up on the https://demo.nextacular.co/account page. This happens because on the first render of the AccountLayout, the getSession()'s data object is not ready and the user gets incorrectly re-directed to /auth/login. Within the AuthLayout, the getSession()->data is checked again, it is found to be valid and then the user is re-directed to https://demo.nextacular.co/account/.

This pull-request attempts to fix the issue by waiting until getSession returns a valid data and this is checked using the status object returned by getSession() instead of the data object. This also fixes #28 and #20

Please note: Since there are no existing test cases, I couldn't test these changes on the nextacular demo site but I did test it out on the code base for my personal project. I would be happy to revise the changes if required.

- Load or re-direct pages based on getSession()->status instead of data
@vercel
Copy link

vercel bot commented Sep 12, 2022

@madhurjain is attempting to deploy a commit to the Nextacular Team on Vercel.

A member of the Team first needs to authorize it.

@arjayosma
Copy link
Collaborator

Hi @madhurjain, I'll review this PR now. Thanks for the amazing job.

Copy link
Collaborator

@arjayosma arjayosma left a comment

Choose a reason for hiding this comment

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

Code works and is a lifesaver.

If you wish to use the data object, ensure that you access it after status === 'authenticated'.

@arjayosma arjayosma merged commit ee4e0b2 into nextacular:main Sep 12, 2022
@WebDev-Akhil
Copy link
Contributor

WebDev-Akhil commented Sep 17, 2022

@madhurjain @arjayosma

I don't think this PR fixed #28.

The workspace dashboard stills returns white page (eg. http://localhost:3000/account/test1)

I think this is because of useWorkspace() not loading when the user reloads the page.

In src/pages/account/[workspaceSlug]/index.js, if you replace the current return with something static (example code below) then it will work but if you want to consume useWorkspace() it doesn't work

the below works on reload (as it is static)

return (
  <AccountLayout>
    <Meta title={`Nextacular - some hardcoded name | Dashboard`} />
    <Content.Title
      title="some hardcoded name"
      subtitle="This is your project's workspace"
    />
    <Content.Divider />
    <Content.Container />
  </AccountLayout>
);

the below doesn't works (as it consumes useWorkspace() and, on page reload it is not being fetched)

return (
    workspace && (
      <AccountLayout>
        <Meta title={`Nextacular - ${workspace.name} | Dashboard`} />
        <Content.Title
          title={workspace.name}
          subtitle="This is your project's workspace"
        />
        <Content.Divider />
        <Content.Container />
      </AccountLayout>
    )
  );

Correct me if I'm wrong

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.

White page on refresh
3 participants