Coder Social home page Coder Social logo

Comments (9)

dbarrosop avatar dbarrosop commented on June 11, 2024

Hi,
you have a comprehensive example here: https://github.com/nhost/nhost/tree/main/examples/quickstarts/nextjs-server-components

There is also some SSR stuff here: https://github.com/nhost/nhost/blob/main/examples/nextjs/pages/public-ssr.tsx

Unfortunately, there are too many ways to do different things with Next.js, making it challenging to cover all in a single example. As a result, various things may be illustrated across different examples :(

Regards

from nhost.

jovermier avatar jovermier commented on June 11, 2024

The SSR example shows how to set the session using the pages router in nextjs but this approach I don't think is compatible with app router. The server components example using app router does not show how to configure NhostProvider nor NhostApolloProvider.

from nhost.

jovermier avatar jovermier commented on June 11, 2024

I created a repo based off of the nhost server components quickstart project. It is still very buggy but with the issue mentioned in the original post. It does implement SSR data fetch, CSR data fetch, and CSR subscriptions.

I had to do some hacking on the NhostSession cookie as the different nhost packages seem to expect different formats.

https://github.com/jovermier/nhost-nextjs-app-router

from nhost.

dbarrosop avatar dbarrosop commented on June 11, 2024

I created a repo based off of the nhost server components quickstart project.

Great, this is very cool. I will ask a colleague to take a look. Is there anything in particular you need help with here?

I had to do some hacking on the NhostSession cookie as the different nhost packages seem to expect different formats.

What do you mean? Could you point me to the inconsistencies, please? AFAICT the only valid type for the NhostSession is the one defined here

from nhost.

jovermier avatar jovermier commented on June 11, 2024

The quickstart nextjs-server-components example base64 encodes the session. I wasn't sure what the reason for that was. The @nhost/nextjs and @nhost/react packages seem to set the cookie not base64 encoded.

const initialSession: NhostSession = JSON.parse(atob(sessionCookieValue) || 'null')

I am going to continue working on the example project today to better demonstrate the challenges keeping the auth state in sync.

from nhost.

jovermier avatar jovermier commented on June 11, 2024

I also added auth state on the home page. This produces error Error: Text content does not match server-rendered HTML. This demonstrates some of the weirdness around keeping the state synced.

Logging in and out does not invalidate the cache on the client rendered components. I would have expected the @nhost/nextjs version to properly handle this.

from nhost.

jovermier avatar jovermier commented on June 11, 2024

Here is an example of coming back to localhost after an hour. The refresh token in the browser automatically gets a user session but hasura claims and the session are null.

Auth Sync Screenshot

from nhost.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.