Hey We have this kind of scenario We have 2 backen...
# support-questions-legacy
u
Hey We have this kind of scenario We have 2 backend on different ports (say 9002 and 9003), both configured to use superTokens and the apiDomain for them is http://localhost Due to which they are able to share the accessToken between them Problem arises when my frontend needs to access both backend, but my configuration looks like this if (typeof window !== "undefined") { SuperTokens.init({ // enableDebugLogs: true, appInfo: { apiDomain: "http://localhost:9002", apiBasePath: "/auth", appName: "...", }, recipeList: [Session.init(), EmailPassword.init()], }); Due to which we are only able to access 9002 server I tried to change apiDomain to "http://localhost" only, it doesnt work(infact i cant use both backends)
r
hey @ubisage
u
Hey
r
you can do something like this on the frontend's session.init:
Copy code
Session.init({
            override: {
                functions: (oI) => {
                    return {
                        ...oI,
                        shouldDoInterceptionBasedOnUrl: (toCheckUrl, apiDomain) => {
                            if (toCheckUrl.startsWith('http://localhost:9002') || toCheckUrl.startsWith("http://localhost:9003")) {
                                return true;
                            }
                            return false;
                        }
                    }
                }
            }
        }),
u
So problem is intact On both backends , for apiDomain we used value of http://localhost only but in frontend it only works if we mention the complete url (http://localhost:9002) instead of http://localhost
override didnt work
r
on the backends, you need to use the right apiDomain as well - based on the current backend
and on the frontend, set the apiDomain to http://localhost:9002
also, you can log info in the override and see if it's returning true or not for the right input
u
how u deal with microservices ?
r
usually there is just one service that the frontend queries
and the approach i mentioned above should work
so try and see why it's not
u
import SuperTokens from "supertokens-web-js"; import Session from "supertokens-web-js/recipe/session"; import EmailPassword from "supertokens-web-js/recipe/emailpassword"; if (typeof window !== "undefined") { SuperTokens.init({ // enableDebugLogs: true, appInfo: { apiDomain: "http://localhost:9002", apiBasePath: "/auth", appName: "pasadonia", }, recipeList: [Session.init({ override: { functions: (oI) => { return { ...oI, shouldDoInterceptionBasedOnUrl: (toCheckUrl, apiDomain) => { console.log(toCheckUrl) if (toCheckUrl.startsWith('http://localhost:9002') || toCheckUrl.startsWith("http://localhost:9003")) { return true; } return false; } } } } }), EmailPassword.init()], }); } This is whats my _app.js looks like With this configuration all the api requests to 9002 have cookies in them( sAccessToken +sFrontToken and st-last-access-token-update ) But the calls made to 9003 dont have cookies in them? What could be the reason its not working?
r
Are you seeing the output from
console.log(toCheckUrl)
?
u
no
it doesnt come up anywhere in console
r
Right. You may be using an older version of the SDK. Which version?
u
"supertokens-web-js": "^0.6.0",
r
and in your package-lock.json, what versinon of supertokens-website is there?
u
"node_modules/supertokens-website": { "version": "17.0.0", "resolved": "https://registry.npmjs.org/supertokens-website/-/supertokens-website-17.0.0.tgz", "integrity": "someValueHere", "dependencies": { "browser-tabs-lock": "^1.3.0", "supertokens-js-override": "^0.0.4" } },
r
right. Do
npm i supertokens-website@17.0.4
and try again
u
ok
Thanks ! Works smoothly