Code Monkey home page Code Monkey logo

Comments (6)

kant01ne avatar kant01ne commented on June 14, 2024

Closing as there is actually no point having supertokens-website to be used server side anyway. The fix (the recognised good practice I should say), is to conditionally initialise SuperTokens if window is defined when doing SSR. This will be mentioned in the guide.

from supertokens-website.

rishabhpoddar avatar rishabhpoddar commented on June 14, 2024

Is to conditionally initialise SuperTokens if window is defined when doing SSR

This means that it's upto the user to initialise it or not? If yes, then I prefer to know have the user have to do this cause it's yet another thing to communicate (and most likely will be missed)

from supertokens-website.

kant01ne avatar kant01ne commented on June 14, 2024

We can add a check for window object at the beginning of the init function.

Pros:

  • It removes the type check line from the guide.

Cons:

  • We are adding custom code that's only for SSR support in our client side package. Any side effects we didn't think of?

NextJS is great in theory but 100% of modern client-side packages have not been designed with SSR in mind. It means that someone using SSR is going to have those window typechecks everywhere in his code and it's going to become a pattern for them. Maybe extract all those client side only libs to one file?
So I don't think it actually brings any complexity but to be extra safe we can do it.

Wdyt?

Link to the draft of the guide for reference: Readme of https://github.com/NkxxkN/supertokens-nextjs-demo (In progress)

from supertokens-website.

rishabhpoddar avatar rishabhpoddar commented on June 14, 2024

So i prefer to achieve two outcomes:

  • There should not be any complexity (from user's point of view) to implement us for SSR
  • for future changes to the libs, the complexity to the user should ideally not increase at all.

I leave it up to you to decide what's best. If we are going to specify it in docs, we need to make sure it's easily findable for people who use SSR.

We should also add good error messages in the lib wherever we are using the window object in case it does not exist. The error message should clearly indicate that if you are using SSR, then you need to do ... in order to fix this error.

from supertokens-website.

kant01ne avatar kant01ne commented on June 14, 2024

Error messages:

In supertokens-auth-react in getInstanceOrThrow()

If window is defined:
SuperTokens must be initialized before calling this method.

If window is undefined:
SuperTokens must be initialized before calling this method. If you are trying to use this method doing server-side-rendering, please make sure you move this call inside a componentDidMount method or useEffect hook.

Anytime the window object is accessed and not available in both supertokens-auth-react and supertokens-website:

If you are using this package with server-side rendering, please make sure that you are checking if the window object is defined.

from supertokens-website.

kant01ne avatar kant01ne commented on June 14, 2024

This was fixed in supertokens-auth-react and in https://github.com/supertokens/supertokens-website/commits/master

from supertokens-website.

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.