ensure other query params are included when there is an existing ?next=

This commit is contained in:
Alaister Young authored and Joshen Lim committed 2022-11-22 16:41:05 +08:00
1 parent 39b58e99ec
commit ec9cd56e27
2 files changed
+4 -9

No files matched your search

+2 -2
View File
@@ -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>
+2 -7
View File
@@ -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') {