One Calendar is a privacy-first calendar web app built with Next.js. It has modern security features, including e2ee, password-protected sharing, and self-destructing share links ๐Ÿ“… calendar.xyehr.cn
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #143 from EvanTechDev/codex/fix-auth-wait-component-display-issue

fix: show auth waiting while Clerk validates __session cookie

authored by

Evan Huang and committed by
GitHub
2b3d5ab7 a9eb8257

+9 -32
+9 -32
app/(app)/app/page.tsx
··· 3 3 import Calendar from "@/components/app/calendar" 4 4 import AuthWaitingLoading from "@/components/app/auth-waiting-loading" 5 5 import { useUser } from "@clerk/nextjs" 6 - import { useEffect, useMemo, useState } from "react" 6 + import { useMemo, useState } from "react" 7 7 8 - const AUTH_FLOW_ROUTES = ["/sign-in", "/sign-up", "/reset-password", "/sso-callback"] 8 + function hasClerkSessionCookie() { 9 + if (typeof document === "undefined") return false 9 10 10 - function isFromAuthFlow(referrer: string) { 11 - if (!referrer) return false 12 - 13 - try { 14 - const refUrl = new URL(referrer) 15 - return AUTH_FLOW_ROUTES.some((route) => refUrl.pathname.includes(route)) 16 - } catch { 17 - return false 18 - } 11 + return document.cookie 12 + .split(";") 13 + .some((cookie) => cookie.trim().startsWith("__session=")) 19 14 } 20 15 21 16 export default function Home() { 22 17 const { isLoaded } = useUser() 23 - const [cameFromAuthFlow, setCameFromAuthFlow] = useState(false) 24 - const [showDelayedWait, setShowDelayedWait] = useState(false) 25 - 26 - useEffect(() => { 27 - setCameFromAuthFlow(isFromAuthFlow(document.referrer)) 28 - }, []) 29 - 30 - useEffect(() => { 31 - if (!cameFromAuthFlow || isLoaded) { 32 - setShowDelayedWait(false) 33 - return 34 - } 35 - 36 - const timer = window.setTimeout(() => { 37 - setShowDelayedWait(true) 38 - }, 300) 39 - 40 - return () => window.clearTimeout(timer) 41 - }, [cameFromAuthFlow, isLoaded]) 18 + const [hasSessionCookie] = useState(hasClerkSessionCookie) 42 19 43 20 const shouldShowAuthWait = useMemo(() => { 44 - return cameFromAuthFlow && !isLoaded && showDelayedWait 45 - }, [cameFromAuthFlow, isLoaded, showDelayedWait]) 21 + return hasSessionCookie && !isLoaded 22 + }, [hasSessionCookie, isLoaded]) 46 23 47 24 if (shouldShowAuthWait) { 48 25 return <AuthWaitingLoading />