mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
ensure other query params are included when there is an existing ?next=
This commit is contained in:
1 parent
39b58e99ec
commit
ec9cd56e27
2 files changed
+4
-9
No files matched your search
@@ -2,7 +2,7 @@ import { ComponentType, useEffect } from 'react'
|
||||
import Head from 'next/head'
|
||||
import { NextRouter, useRouter } from 'next/router'
|
||||
|
||||
import { STORAGE_KEY } from 'lib/gotrue'
|
||||
import { getNextPath, STORAGE_KEY } from 'lib/gotrue'
|
||||
import { IS_PLATFORM } from 'lib/constants'
|
||||
import { useProfile, useStore, usePermissions } from 'hooks'
|
||||
import Error500 from '../../pages/500'
|
||||
@@ -86,7 +86,7 @@ export function withAuth<T>(
|
||||
to the login page if they are guaranteed (no token at all) to not be logged in. */}
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `if (!localStorage.getItem('${STORAGE_KEY}') && !location.hash) {location.replace('/sign-in?next=' + (new URLSearchParams(location.search).get('next') || encodeURIComponent(location.pathname + location.search + location.hash)))}`,
|
||||
__html: `window._getNextPath = ${getNextPath.toString()};if (!localStorage.getItem('${STORAGE_KEY}') && !location.hash) {location.replace('/sign-in?next=' + window._getNextPath(location.pathname))}`,
|
||||
}}
|
||||
/>
|
||||
</Head>
|
||||
|
||||
@@ -40,18 +40,13 @@ export const getIdentity = (gotrueUser: User) => {
|
||||
|
||||
// NOTE: do not use any imports in this function,
|
||||
// as it is use standalone in the documents head
|
||||
export const getNextPath = () => {
|
||||
if (typeof window === 'undefined') {
|
||||
// make sure this method is SSR safe
|
||||
return '/projects'
|
||||
}
|
||||
|
||||
export const getNextPath = (fallback = '/projects') => {
|
||||
const searchParams = new URLSearchParams(location.search)
|
||||
const returnTo = searchParams.get('next')
|
||||
|
||||
searchParams.delete('next')
|
||||
|
||||
const next = returnTo ?? '/projects'
|
||||
const next = returnTo ?? fallback
|
||||
const remainingSearchParams = searchParams.toString()
|
||||
|
||||
if (next === 'new-project') {
|
||||
|
||||
Reference in new issue
Block a user