Hey all, is there a recommendation for how best to...
# support-questions
g
Hey all, is there a recommendation for how best to handle using SuperTokens in a setting where the domain name(s) are unpredictable? My use case is we have ephemeral preview apps created for each pull request, each on a different domain name. I was hoping I could pass an empty string for
websiteDomain
and
apiDomain
to indicate using the current host – something like that. We get an "Error: Please provide a valid domain name" message when doing this, however. It's possible for us to pass through the current domain name all the way from our CI, but it's a bit fiddly – wondering if there's a better way.
r
Hey @goodgravy
We are working on making this more flexible, but until then, you can pass in some random websiteDomain and set the cookieSameSite setting in session.init to the right value manually.
You can also override the sendEmail functions to change the random domain name in the password reset / email verification links to what’s present in the request’s origin
g
@rp could you explain this workaround some more? If I use e.g. http://example.com for the websiteDomain, I'm redirected there use
redirectToAuth
. It seems the backend and the frontend – anywhere there's appInfo usage going on – is going to need to explicitly specify the current domain, no?
(Part of the issue here is that we like to use the same docker images between pre-prod and prod, so baking domain names into them is problematic – which is what the Next.js build process does when you access process.env)
r
So on the frontend, you can use location.origin as the websiteDomain value
Is there some sort of regex / conman parts to the website and api domains for previewing and production?
g
Yes, there are predictable elements in the various domains. I was expecting from the behaviour of redirectToAuth, however, that I'd need to know the exactly correct domain for SuperTokens to work, though? Seems I'm missing something…
r
well, on the frontend, you can use location.origin as the websiteDomain. On the backend, you can set it to any valid domain and override the sendEmail functions (see email delivery section in our docs) to change the domain in the links based on the request's origin. I know i have said this previously, but this is as clear as i can get without knowing much about your setup.
2 Views