The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
include remaining query string in next path
Alaister Young2383efe38e14
diff --git a/studio/components/interfaces/SignIn/SignInForm.tsx b/studio/components/interfaces/SignIn/SignInForm.tsxindex c5cd86ec3a2..b65f297bcaf 100644--- a/studio/components/interfaces/SignIn/SignInForm.tsx+++ b/studio/components/interfaces/SignIn/SignInForm.tsx@@ -1,6 +1,5 @@import HCaptcha from '@hcaptcha/react-hcaptcha'import { useStore } from 'hooks'-import { useParams } from 'hooks/misc/useParams'import { auth, getNextPath } from 'lib/gotrue'import Link from 'next/link'import { useRouter } from 'next/router'@@ -17,7 +16,6 @@ const signInSchema = object({const SignInForm = () => {const { ui } = useStore()const router = useRouter()- const { next: returnTo } = useParams()const { cache } = useSWRConfig()const [captchaToken, setCaptchaToken] = useState<string | null>(null)@@ -52,7 +50,7 @@ const SignInForm = () => {// @ts-ignorecache.clear()- await router.push(getNextPath(returnTo))+ await router.push(getNextPath())} else {setCaptchaToken(null)captchaRef.current?.resetCaptcha()diff --git a/studio/components/interfaces/SignIn/SignInWithGitHub.tsx b/studio/components/interfaces/SignIn/SignInWithGitHub.tsxindex 39c952ecf84..96d21e5cfd4 100644--- a/studio/components/interfaces/SignIn/SignInWithGitHub.tsx+++ b/studio/components/interfaces/SignIn/SignInWithGitHub.tsx@@ -1,10 +1,7 @@-import { useParams } from 'hooks'import { auth, getNextPath } from 'lib/gotrue'import { Button, IconGitHub } from 'ui'const SignInWithGitHub = () => {- const { next: returnTo } = useParams()-async function handleGithubSignIn() {try {const { error } = await auth.signInWithOAuth({@@ -14,7 +11,7 @@ const SignInWithGitHub = () => {process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview'? process.env.NEXT_PUBLIC_VERCEL_URL: process.env.NEXT_PUBLIC_SITE_URL- }${getNextPath(returnTo)}`,+ }${getNextPath()}`,},})if (error) throw errordiff --git a/studio/components/layouts/SignInLayout/SignInLayout.tsx b/studio/components/layouts/SignInLayout/SignInLayout.tsxindex 0505e061267..31778e90284 100644--- a/studio/components/layouts/SignInLayout/SignInLayout.tsx+++ b/studio/components/layouts/SignInLayout/SignInLayout.tsx@@ -1,5 +1,5 @@import { useStore } from 'hooks'-import { STORAGE_KEY } from 'lib/gotrue'+import { getNextPath, STORAGE_KEY } from 'lib/gotrue'import { observer } from 'mobx-react-lite'import Head from 'next/head'import Image from 'next/image'@@ -43,15 +43,7 @@ const SignInLayout = ({<Head><scriptdangerouslySetInnerHTML={{- __html: `if (localStorage.getItem('${STORAGE_KEY}')) {- let returnTo = new URLSearchParams(location.search).get('next') ?? '/projects'-- if (returnTo === 'new-project') {- returnTo = '/new/new-project'- }-- location.replace(returnTo)- }`,+ __html: `window._getNextPath = ${getNextPath.toString()};if (localStorage.getItem('${STORAGE_KEY}')) {location.replace(window._getNextPath())}`,}}/></Head>diff --git a/studio/hooks/misc/useAutoAuthRedirect.tsx b/studio/hooks/misc/useAutoAuthRedirect.tsxindex c67d948fa41..118cf4d6c47 100644--- a/studio/hooks/misc/useAutoAuthRedirect.tsx+++ b/studio/hooks/misc/useAutoAuthRedirect.tsx@@ -32,7 +32,7 @@ function useAutoAuthRedirect() {// @ts-ignorecache.clear()- await router.push(getNextPath(returnTo))+ await router.push(getNextPath())}})()}, [])diff --git a/studio/lib/gotrue.ts b/studio/lib/gotrue.tsindex 905dcacbfa6..97c7612be77 100644--- a/studio/lib/gotrue.ts+++ b/studio/lib/gotrue.ts@@ -38,12 +38,20 @@ export const getIdentity = (gotrueUser: User) => {}}-export const getNextPath = (path?: string | null) => {- let next = path ?? '/projects'+// NOTE: do not use any imports in this function,+// as it is use standalone in the documents head+export const getNextPath = () => {+ const searchParams = new URLSearchParams(location.search)+ const returnTo = searchParams.get('next')++ searchParams.delete('next')++ const next = returnTo ?? '/projects'+ const remainingSearchParams = searchParams.toString()if (next === 'new-project') {- return '/new/new-project'+ return '/new/new-project' + (remainingSearchParams ? `?${remainingSearchParams}` : '')}- return next+ return next + (remainingSearchParams ? `?${remainingSearchParams}` : '')}