Comments (6)
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.
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.
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.
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.
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.
This was fixed in supertokens-auth-react and in https://github.com/supertokens/supertokens-website/commits/master
from supertokens-website.
Related Issues (20)
- Copy paste code samples with firefox does not copy newlines HOT 1
- Calling session refresh on sign out (due to 401) throws error when refresh API blocked with chrome HOT 1
- doesSessionExists should check the front-token validity and refresh if necessary HOT 6
- Do not rely on front-token if st-access-token is available
- Restructure/split up fetch.ts
- Infinite session refresh HOT 5
- Add refresh token to refresh request in header based auth even if access token is missing HOT 1
- Allow disabling interceptors for user API calls HOT 3
- make setting headers in request object consistent
- Support Module Augmentation in TypeScript
- XHR interceptor not respecting axios interceptor HOT 8
- Axios interceptor uses stale access token after refresh
- Using multiple auth providers at the same time can cause an infinite refresh loop
- Fetch interceptor breaks fetch api. HOT 1
- Allow interception for different ports on the same domain HOT 1
- Empty response header for st-access-token and st-refresh-token are removed by Vercel proxy HOT 2
- Fetch interceptor causing error in development when using an ad blocker HOT 3
- Do not store tokens in frontend cookies by default in header based auth
- localStorage Safari Security Error when users have "Block Cookies" setting enabled HOT 5
- Support interception if request made to relative path HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supertokens-website.