Skip to main content
Which UI do you use?
Custom UI
Pre built UI

Using in an iframe

If your website can be embedded in an iframe which is consumed by other websites, then this section is for you.

info

If the sites in which your iframe can be embedded share the same top level domain as the iframe domain, then you can ignore this section.

Frontend changes#

  • Set isInIframe to true during Session.init on the frontend.
  • You will need to use https during testing / dev for this to work. You can use tools like ngrok to create a dev env with https on your website / API domain.
import SuperTokens from "supertokens-auth-react";
import Session from "supertokens-auth-react/recipe/session";

SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
Session.init({
isInIframe: true
})
]
});

Backend changes#

important

Make the changes below only if your CORS setting allows any origin to query your API. Ignore these backend changes if your iframe is only allowed to work within certain trusted sites (and you have whitelisted them via the allowed origins config in your CORS setting).

import SuperTokens from "supertokens-node";
import Session from "supertokens-node/recipe/session";

SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
Session.init({
cookieSameSite: "none",
antiCsrf: "VIA_TOKEN"
})
]
});

A note on Safari and Chrome (Incognito mode only)#

The default behaviour for these is that third party cookies / localstorage are blocked. This means that sessions will not work, and we should instead show the user instructions on how to enable them (depending on their browser)