@@ -39,6 +39,15 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3939
4040type ControlAction = "forward" | "backward" | "turn_left" | "turn_right" | "use" ;
4141
42+ const stripSensitiveLeaderboardFields = ( entry : LeaderboardEntry ) : LeaderboardEntry => {
43+ const { oauthProvider, oauthUserId, ...rest } = entry ;
44+ return {
45+ ...( rest as LeaderboardEntry ) ,
46+ oauthProvider : undefined ,
47+ oauthUserId : undefined ,
48+ } ;
49+ } ;
50+
4251function createSessionId ( ) {
4352 return `session-${ Date . now ( ) . toString ( 36 ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 8 ) } ` ;
4453}
@@ -536,7 +545,8 @@ export default function GamePage() {
536545 const merged = Array . isArray ( parsed ) ? [ ...parsed , entry ] : [ entry ] ;
537546 sortLeaderboard ( merged ) ;
538547 const top = merged . slice ( 0 , 50 ) ;
539- window . localStorage . setItem ( LEADERBOARD_STORAGE_KEY , JSON . stringify ( top ) ) ;
548+ const publicTop = top . map ( stripSensitiveLeaderboardFields ) ;
549+ window . localStorage . setItem ( LEADERBOARD_STORAGE_KEY , JSON . stringify ( publicTop ) ) ;
540550 setLeaderboardEntries ( top . slice ( 0 , 10 ) ) ;
541551 } ;
542552
@@ -555,9 +565,11 @@ export default function GamePage() {
555565 if ( payload . ok && Array . isArray ( payload . entries ) ) {
556566 setLeaderboardEntries ( payload . entries ) ;
557567 if ( typeof window !== "undefined" ) {
568+ const topEntries = payload . entries . slice ( 0 , 50 ) ;
569+ const publicTopEntries = topEntries . map ( stripSensitiveLeaderboardFields ) ;
558570 window . localStorage . setItem (
559571 LEADERBOARD_STORAGE_KEY ,
560- JSON . stringify ( payload . entries . slice ( 0 , 50 ) ) ,
572+ JSON . stringify ( publicTopEntries ) ,
561573 ) ;
562574 }
563575 return ;
0 commit comments