Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: listen to multi-tab sign-in

Stojan Dimitrovskidb34626b6cef
diff --git a/studio/pages/sign-in.tsx b/studio/pages/sign-in.tsx
index c9fbefdb8cc..a98b3b31dcc 100644
--- a/studio/pages/sign-in.tsx
+++ b/studio/pages/sign-in.tsx
@@ -8,6 +8,7 @@ import { SignInLayout } from 'components/layouts'
import { useEffect } from 'react'
import { IS_PLATFORM } from 'lib/constants'
import { useRouter } from 'next/router'
+import { auth } from 'lib/gotrue'
const SignInPage: NextPageWithLayout = () => {
const router = useRouter()
@@ -15,6 +16,20 @@ const SignInPage: NextPageWithLayout = () => {
// if the dashboard is running locally, redirect straight to the projects page
if (!IS_PLATFORM) {
router.replace('/projects')
+ return
+ }
+
+ const {
+ data: { subscription },
+ } = auth.onAuthStateChange((event) => {
+ if (event === 'SIGNED_IN') {
+ // if user has signed in on another tab, take them to the home page
+ router.replace('/projects')
+ }
+ })
+
+ return () => {
+ subscription.unsubscribe()
}
}, [])