fix: add correct login button instead of sending everyone to my pages

This commit is contained in:
Christel Westerberg
2024-11-01 13:08:00 +01:00
parent e547f8c83e
commit e2e2d786bd
7 changed files with 27 additions and 17 deletions

View File

@@ -1,16 +1,27 @@
"use client"
import { usePathname } from "next/navigation"
import { usePathname, useSearchParams } from "next/navigation"
import { useEffect, useState } from "react"
/*** This hook is used to get the current pathname (as reflected in window.location.href) of the page. During ssr, the value from usePathname()
* is the value return from NextResponse.rewrite() (e.g. the path from the app directory) instead of the actual pathname from the URL.
*/
export function useLazyPathname() {
export function useLazyPathname({ includeSearchParams = false } = {}) {
const pathName = usePathname()
const searchParams = useSearchParams()
const [updatedPathName, setUpdatedPathName] = useState<string | null>(null)
useEffect(() => {
setUpdatedPathName(pathName)
}, [pathName])
return updatedPathName ? updatedPathName : null
if (!includeSearchParams) {
setUpdatedPathName(pathName)
} else {
const updatedPathname = searchParams.size
? `${pathName}?${searchParams.toString()}`
: pathName
setUpdatedPathName(updatedPathname)
}
}, [pathName, searchParams, includeSearchParams])
return updatedPathName
}