File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { useEffect } from "react" ;
22import { useOrySession } from "@/lib/OrySessionContext" ;
3+ import { getCookie } from "@/lib/utils" ;
34
45export function PlaceholderReplacer ( ) {
56 const { email, loading } = useOrySession ( ) ;
67
78 useEffect ( ( ) => {
8- // Determine the replacement value
9+ // Determine the replacement value with fallback priority:
10+ // 1. If loading, keep original placeholder
11+ // 2. If Ory email is available, use that (highest priority)
12+ // 3. If no Ory email but cookie exists, use cookie value
13+ // 4. Otherwise, use original placeholder
14+ const getCookieEmail = ( ) => getCookie ( "last_arcadedev_account_email" ) ;
15+
916 const replacement = loading
1017 ? "{arcade_user_id}" // Keep original while loading
11- : email || "{arcade_user_id}" ;
18+ : email || getCookieEmail ( ) || "{arcade_user_id}" ;
1219
1320 // Function to replace text in a text node
1421 const replaceInTextNode = ( node : Text ) => {
Original file line number Diff line number Diff line change @@ -4,3 +4,17 @@ import { twMerge } from "tailwind-merge";
44export function cn ( ...inputs : ClassValue [ ] ) {
55 return twMerge ( clsx ( inputs ) ) ;
66}
7+
8+ /**
9+ * Read a cookie value by name from document.cookie
10+ * @param name - The name of the cookie to read
11+ * @returns The cookie value or null if not found
12+ */
13+ export function getCookie ( name : string ) : string | null {
14+ const value = `; ${ document . cookie } ` ;
15+ const parts = value . split ( `; ${ name } =` ) ;
16+ if ( parts . length === 2 ) {
17+ return parts . pop ( ) ?. split ( ";" ) . shift ( ) || null ;
18+ }
19+ return null ;
20+ }
You can’t perform that action at this time.
0 commit comments