client: redirect unauthed users from all /new paths
This commit is contained in:
parent
454ea303a6
commit
4177897691
3 changed files with 3 additions and 3 deletions
|
@ -18,6 +18,7 @@ import CreatedAgoBadge from "@components/badges/created-ago-badge"
|
||||||
import Cookies from "js-cookie"
|
import Cookies from "js-cookie"
|
||||||
import PasswordModalPage from "./password-modal-wrapper"
|
import PasswordModalPage from "./password-modal-wrapper"
|
||||||
import VisibilityControl from "@components/badges/visibility-control"
|
import VisibilityControl from "@components/badges/visibility-control"
|
||||||
|
import useSharedState from "@lib/hooks/use-shared-state"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
post: Post
|
post: Post
|
||||||
|
@ -34,6 +35,7 @@ const PostPage = ({ post: initialPost, isProtected }: Props) => {
|
||||||
const [isOwner] = useState(
|
const [isOwner] = useState(
|
||||||
post.users ? post.users[0].id === Cookies.get("drift-userid") : false
|
post.users ? post.users[0].id === Cookies.get("drift-userid") : false
|
||||||
)
|
)
|
||||||
|
const [signedIn] = useSharedState<boolean>("signedIn")
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const isMobile = useMediaQuery("mobile")
|
const isMobile = useMediaQuery("mobile")
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import Cookies from "js-cookie"
|
import Cookies from "js-cookie"
|
||||||
import { useRouter } from "next/router"
|
|
||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
import useSharedState from "./use-shared-state"
|
import useSharedState from "./use-shared-state"
|
||||||
|
|
||||||
|
@ -9,7 +8,6 @@ const useSignedIn = () => {
|
||||||
typeof window === "undefined" ? false : !!Cookies.get("drift-token")
|
typeof window === "undefined" ? false : !!Cookies.get("drift-token")
|
||||||
)
|
)
|
||||||
const token = Cookies.get("drift-token")
|
const token = Cookies.get("drift-token")
|
||||||
const router = useRouter()
|
|
||||||
const signin = (token: string) => {
|
const signin = (token: string) => {
|
||||||
setSignedIn(true)
|
setSignedIn(true)
|
||||||
// TODO: investigate SameSite / CORS cookie security
|
// TODO: investigate SameSite / CORS cookie security
|
||||||
|
|
|
@ -45,7 +45,7 @@ export function middleware(req: NextRequest, event: NextFetchEvent) {
|
||||||
return NextResponse.redirect(getURL("new"))
|
return NextResponse.redirect(getURL("new"))
|
||||||
}
|
}
|
||||||
} else if (!signedIn) {
|
} else if (!signedIn) {
|
||||||
if (pathname === "/new") {
|
if (pathname.startsWith("/new")) {
|
||||||
return NextResponse.redirect(getURL("signin"))
|
return NextResponse.redirect(getURL("signin"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue