Hey, has anyone tackled multi-domain auth yet? Or ...
# help
m
Hey, has anyone tackled multi-domain auth yet? Or even multi-subdomain auth? How do you do it? How would you do it? It doesn't look like there's a config option to set the cookie domain yet, right?
b
Yeah I do it.
You put your list of domains in the dashboard separated by commas then in your client you set the return to parameter. Let me look at it.
m
Ok, thanks!
b
Under Auth Settings "Additional Redirect URLs". you put your urls separated by commas.
m
Cool, so that gets you auth via multiple domains. Do you know anything about setting the cookie domain to say
example.com
so that a user can stay logged in across
www.
and
app.
?
b
Then in my client code I do this:
Copy code
public signInWithProvider = async (provider: Provider) => {
    const { user, session, error } = await supabase.auth.signIn({
      // provider can be:
      // 'azure','bitbucket','facebook','github','gitlab','google','twitter','apple'
      provider: provider
    },{
      redirectTo: window.location.origin
    });
    return { user, session, error };
  }
where
window.location.origin
is the domain they're authentication from, which is usualy
localhost:8100
or something like that while in development, or any of of my other domains in the redirect URL's list.
I don't know about www vs. the root domain, I have my domains set up to redirect to the root domain anyway so it's never a problem.
m
I'm thinking I'd probably have to roll my own client if I switched. The cookie trick is that any subdomain can read a root cookie, so a user session automatically transfers. But my app is a multi-tenant app, so I can end up with thousands of domains sharing the same user table.
(These are two different use cases I'm trying to support, not one big one.)
In any case, thanks for the info!
b
Good luck with this!