Replies: 11 comments 22 replies
-
Did you find any solution to this? facing the same issue.. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, I'm on the Auth team. If I understand correctly, your question is about whether two different apps, that exist both on This is definitely doable, but it's not well documented. When using Auth Helpers You can pass a When using the JS library on your own You can do this by using a hand-crafted cookie using the In both of your applications, you need to add code similar to this: supabase.auth.onAuthStateChange((event, session) => {
if (event === 'SIGNED_OUT' || event === 'USER_DELETED') {
// delete cookies on sign out
const expires = new Date(0).toUTCString()
document.cookie = `my-access-token=; Domain=example.com; path=/; expires=${expires}; SameSite=Lax; secure`
document.cookie = `my-refresh-token=; Domain=example.com; path=/; expires=${expires}; SameSite=Lax; secure`
} else if (event === 'SIGNED_IN' || event === 'TOKEN_REFRESHED') {
const maxAge = 100 * 365 * 24 * 60 * 60 // 100 years, never expires
document.cookie = `my-access-token=${session.access_token}; Domain=example.com; path=/; max-age=${maxAge}; SameSite=Lax; secure`
document.cookie = `my-refresh-token=${session.refresh_token}; Domain=example.com; path=/; max-age=${maxAge}; SameSite=Lax; secure`
}
}) Each time a new access and refresh tokens are issued on any site these cookies will get updated. Then you should also add this code next to the above callback: const cookies = document.cookie.split(/\s*;\s*/).map(cookie => cookie.split('='));
const accessTokenCookie = cookies.find(x => x[0] == 'my-access-token');
const refreshTokenCookie = cookies.find(x => x[0] == 'my-refresh-token');
if (accessTokenCookie && refreshTokenCookie) {
await supabase.auth.setSession({
access_token: accessTokenCookie[1],
refresh_token: refreshTokenCookie[1],
})
} This snippet extracts the cookies (that either of the sites set) and forces the client library to use those. Notice the addition of
If you need multiple domains, you would need to set cookies multiple times with the different top-level domain. Note that this cookie approach does not signal to tabs currently opened on the other site. This is very difficult to do right, but you can improve the user experience by checking for the cookies (as shown in the snippet above) just before you call a |
Beta Was this translation helpful? Give feedback.
-
Example of using Auth helper in Next.js using TS
if authenticate on main page, then the cookie will be available on |
Beta Was this translation helpful? Give feedback.
-
A small bug fix for nextjs app dir users; |
Beta Was this translation helpful? Give feedback.
-
Is there anything about how this works with supabase/ssr? |
Beta Was this translation helpful? Give feedback.
-
Any updates on this? |
Beta Was this translation helpful? Give feedback.
-
Any simple way to do this with nextjs 14? |
Beta Was this translation helpful? Give feedback.
-
Has anyone been able to redirect their users from their main domain (example.com) to their sub-domain (app.example.com) where Predictably, since the project that hosts |
Beta Was this translation helpful? Give feedback.
-
Anyone found a solution to this? I am trying to replicate the Vercel Platforms Starter Kit but cannot get cross-domain auth working with Supabase at all |
Beta Was this translation helpful? Give feedback.
-
If anyone else is running into this I recommend having a look at #27283 (comment) |
Beta Was this translation helpful? Give feedback.
-
Yes it's possible, please see my answer in this issue -> answer |
Beta Was this translation helpful? Give feedback.
-
Hi,
Is it possible to have a session created on app.mydomain.com be valid on *.mydomain.com?
I am hosting a simple landing page on Vercel and it will need to have a logged-in section as well; accessing the user's date to alter the landing page.
On app.mydomain.com will be a separate React app.
I'm considering using Supertokens.io because they are more flexible than Auth0 and it should be possible there. Even better I'd stick with Supabase if this is possible. Anyone here has any idea? :)
Beta Was this translation helpful? Give feedback.
All reactions