The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add last sign in method used to sign in ui (#28631)
Jordi Enric7da83a908013
diff --git a/apps/studio/components/interfaces/SignIn/LastSignInWrapper.tsx b/apps/studio/components/interfaces/SignIn/LastSignInWrapper.tsxnew file mode 100644index 00000000000..37a5732ff23--- /dev/null+++ b/apps/studio/components/interfaces/SignIn/LastSignInWrapper.tsx@@ -0,0 +1,31 @@+import { LastSignInType, useLastSignIn } from 'hooks/misc/useLastSignIn'+import { ReactNode } from 'react'+import { Badge, cn } from 'ui'++export function LastSignInWrapper({+ children,+ type,+}: {+ children: ReactNode+ type: LastSignInType+}) {+ const [lastSignIn] = useLastSignIn()++ return (+ <div className="flex items-center relative">+ {lastSignIn === type && (+ <Badge variant="default" className="absolute -right-[84px]">+ Last used+ </Badge>+ )}+ <div+ className={cn('w-full', {+ 'outline outline-1 outline-offset-4 outline-foreground-lighter/50 rounded-md ':+ lastSignIn === type,+ })}+ >+ {children}+ </div>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/SignIn/SignInForm.tsx b/apps/studio/components/interfaces/SignIn/SignInForm.tsxindex 4b518cd24bc..57b537735f2 100644--- a/apps/studio/components/interfaces/SignIn/SignInForm.tsx+++ b/apps/studio/components/interfaces/SignIn/SignInForm.tsx@@ -11,6 +11,8 @@ import { object, string } from 'yup'import { getMfaAuthenticatorAssuranceLevel } from 'data/profile/mfa-authenticator-assurance-level-query'import { auth, buildPathWithParams, getReturnToPath } from 'lib/gotrue'import { Button, Form, Input } from 'ui'+import { useLastSignIn } from 'hooks/misc/useLastSignIn'+import { LastSignInWrapper } from './LastSignInWrapper'const signInSchema = object({email: string().email('Must be a valid email').required('Email is required'),@@ -20,6 +22,7 @@ const signInSchema = object({const SignInForm = () => {const router = useRouter()const queryClient = useQueryClient()+ const [lastSignIn, setLastSignIn] = useLastSignIn()const [captchaToken, setCaptchaToken] = useState<string | null>(null)const captchaRef = useRef<HCaptcha>(null)@@ -40,6 +43,7 @@ const SignInForm = () => {})if (!error) {+ setLastSignIn('email')try {const data = await getMfaAuthenticatorAssuranceLevel()if (data) {@@ -130,16 +134,18 @@ const SignInForm = () => {/></div>- <Button- block- form="signIn-form"- htmlType="submit"- size="large"- disabled={isSubmitting}- loading={isSubmitting}- >- Sign In- </Button>+ <LastSignInWrapper type="email">+ <Button+ block+ form="signIn-form"+ htmlType="submit"+ size="large"+ disabled={isSubmitting}+ loading={isSubmitting}+ >+ Sign In+ </Button>+ </LastSignInWrapper></div>)}}diff --git a/apps/studio/components/interfaces/SignIn/SignInSSOForm.tsx b/apps/studio/components/interfaces/SignIn/SignInSSOForm.tsxindex 900ce8590e3..1ccb16a750b 100644--- a/apps/studio/components/interfaces/SignIn/SignInSSOForm.tsx+++ b/apps/studio/components/interfaces/SignIn/SignInSSOForm.tsx@@ -8,6 +8,7 @@ import { object, string } from 'yup'import { BASE_PATH } from 'lib/constants'import { auth, buildPathWithParams } from 'lib/gotrue'import { Button, Form, Input } from 'ui'+import { useLastSignIn } from 'hooks/misc/useLastSignIn'const WHITELIST_ERRORS = ['No SSO provider assigned for this domain']@@ -15,7 +16,7 @@ const SignInSSOForm = () => {const queryClient = useQueryClient()const captchaRef = useRef<HCaptcha>(null)const [captchaToken, setCaptchaToken] = useState<string | null>(null)-+ const [lastSignInUsed, setLastSignInUsed] = useLastSignIn()const signInSchema = object({email: string().email('Must be a valid email').required('Email is required'),})@@ -47,7 +48,7 @@ const SignInSSOForm = () => {if (!error) {await queryClient.resetQueries()-+ setLastSignInUsed('sso')if (data) {// redirect to SSO identity provider pagewindow.location.href = data.urldiff --git a/apps/studio/components/interfaces/SignIn/SignInWithGitHub.tsx b/apps/studio/components/interfaces/SignIn/SignInWithGitHub.tsxindex 38345161688..26ef1f02bb4 100644--- a/apps/studio/components/interfaces/SignIn/SignInWithGitHub.tsx+++ b/apps/studio/components/interfaces/SignIn/SignInWithGitHub.tsx@@ -6,10 +6,12 @@ import * as Sentry from '@sentry/nextjs'import { BASE_PATH } from 'lib/constants'import { auth, buildPathWithParams } from 'lib/gotrue'import { Button } from 'ui'+import { useLastSignIn } from 'hooks/misc/useLastSignIn'+import { LastSignInWrapper } from './LastSignInWrapper'const SignInWithGitHub = () => {const [loading, setLoading] = useState(false)-+ const [lastSignInUsed, setLastSignInUsed] = useLastSignIn()async function handleGithubSignIn() {setLoading(true)@@ -30,6 +32,9 @@ const SignInWithGitHub = () => {},})if (error) throw error+ else {+ setLastSignInUsed('github')+ }} catch (error: any) {toast.error(`Failed to sign in via GitHub: ${error.message}`)Sentry.captureMessage('[CRITICAL] Failed to sign in via GH: ' + error.message)@@ -38,17 +43,19 @@ const SignInWithGitHub = () => {}return (- <Button- block- onClick={handleGithubSignIn}- // set the width to 20 so that it matches the loading spinner and don't push the text when loading- icon={<Github width={20} height={18} />}- size="large"- type="default"- loading={loading}- >- Continue with GitHub- </Button>+ <LastSignInWrapper type="github">+ <Button+ block+ onClick={handleGithubSignIn}+ // set the width to 20 so that it matches the loading spinner and don't push the text when loading+ icon={<Github width={20} height={18} />}+ size="large"+ type="default"+ loading={loading}+ >+ Continue with GitHub+ </Button>+ </LastSignInWrapper>)}diff --git a/apps/studio/hooks/misc/useLastSignIn.ts b/apps/studio/hooks/misc/useLastSignIn.tsnew file mode 100644index 00000000000..ad860ebe748--- /dev/null+++ b/apps/studio/hooks/misc/useLastSignIn.ts@@ -0,0 +1,8 @@+import { LOCAL_STORAGE_KEYS } from 'lib/constants'+import { useLocalStorage } from './useLocalStorage'++export type LastSignInType = 'github' | 'email' | 'sso' | null++export function useLastSignIn() {+ return useLocalStorage<LastSignInType>(LOCAL_STORAGE_KEYS.LAST_SIGN_IN_METHOD, null)+}diff --git a/apps/studio/lib/constants/index.ts b/apps/studio/lib/constants/index.tsindex 15a59e212ae..6015c1427a7 100644--- a/apps/studio/lib/constants/index.ts+++ b/apps/studio/lib/constants/index.ts@@ -63,6 +63,9 @@ export const LOCAL_STORAGE_KEYS = {// Used for storing a user id when sending reports to Sentry. The id is hashed for anonymity.SENTRY_USER_ID: 'supabase-sentry-user-id',++ // Used for storing the last sign in method used by the user+ LAST_SIGN_IN_METHOD: 'supabase-last-sign-in-method',}export const OPT_IN_TAGS = {diff --git a/apps/studio/lib/local-storage.ts b/apps/studio/lib/local-storage.tsindex cb8b9bf6d5f..07775331f48 100644--- a/apps/studio/lib/local-storage.ts+++ b/apps/studio/lib/local-storage.ts@@ -11,6 +11,7 @@ const LOCAL_STORAGE_KEYS_ALLOWLIST = [LOCAL_STORAGE_KEYS.UI_PREVIEW_NAVIGATION_LAYOUT,LOCAL_STORAGE_KEYS.UI_PREVIEW_RLS_AI_ASSISTANT,LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS,+ LOCAL_STORAGE_KEYS.LAST_SIGN_IN_METHOD,]export function clearLocalStorage() {diff --git a/apps/studio/pages/sign-in.tsx b/apps/studio/pages/sign-in.tsxindex 817e5161bcc..07e868c50ee 100644--- a/apps/studio/pages/sign-in.tsx+++ b/apps/studio/pages/sign-in.tsx@@ -9,6 +9,7 @@ import SignInLayout from 'components/layouts/SignInLayout/SignInLayout'import { IS_PLATFORM } from 'lib/constants'import type { NextPageWithLayout } from 'types'import { Button } from 'ui'+import { LastSignInWrapper } from 'components/interfaces/SignIn/LastSignInWrapper'const SignInPage: NextPageWithLayout = () => {const router = useRouter()@@ -25,16 +26,18 @@ const SignInPage: NextPageWithLayout = () => {<><div className="flex flex-col gap-5"><SignInWithGitHub />- <Button asChild block size="large" type="outline" icon={<Lock width={18} height={18} />}>- <Link- href={{- pathname: '/sign-in-sso',- query: searchParams,- }}- >- Continue with SSO- </Link>- </Button>+ <LastSignInWrapper type="sso">+ <Button asChild block size="large" type="outline" icon={<Lock width={18} height={18} />}>+ <Link+ href={{+ pathname: '/sign-in-sso',+ query: searchParams,+ }}+ >+ Continue with SSO+ </Link>+ </Button>+ </LastSignInWrapper><div className="relative"><div className="absolute inset-0 flex items-center">