Skip to main content

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.

SuperTokens.init({    appInfo: {...},    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).


SuperTokens.init({    appInfo: {...},    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).

This problem is described in more detail (aloong with solutions) in this GitHub issue.