@@ -93,6 +93,7 @@ import {
9393} from '../common/profile/completion' ;
9494import { getUnreadNotificationsCount } from '../notifications/common' ;
9595import { unwrapArray } from '../common/array' ;
96+ import { asyncRetry } from '../integrations/retry' ;
9697
9798export type BootSquadSource = Omit < GQLSource , 'currentMember' > & {
9899 permalink : string ;
@@ -925,12 +926,17 @@ export const getBootData = async (
925926
926927 const baSessionCookie = req . cookies [ cookies . authSession . key ] ;
927928 if ( baSessionCookie ) {
929+ let sessionInvalid = false ;
928930 try {
929- const session = ( await getBetterAuth ( ) . api . getSession ( {
930- headers : fromNodeHeaders (
931- req . headers as Record < string , string | string [ ] | undefined > ,
932- ) ,
933- } ) ) as BetterAuthSession | null ;
931+ const session = ( await asyncRetry (
932+ ( ) =>
933+ getBetterAuth ( ) . api . getSession ( {
934+ headers : fromNodeHeaders (
935+ req . headers as Record < string , string | string [ ] | undefined > ,
936+ ) ,
937+ } ) ,
938+ { retries : 3 } ,
939+ ) ) as BetterAuthSession | null ;
934940
935941 if ( session ) {
936942 req . userId = session . user . id ;
@@ -947,14 +953,18 @@ export const getBootData = async (
947953 }
948954
949955 req . log . warn ( 'BetterAuth getSession returned null' ) ;
956+ sessionInvalid = true ;
950957 } catch ( error ) {
951958 req . log . error (
952959 { err : error instanceof Error ? error . message : String ( error ) } ,
953960 'BetterAuth session validation failed' ,
954961 ) ;
955962 }
956- req . log . warn ( 'BetterAuth session cookie present but validation failed' ) ;
957- setCookie ( req , res , 'authSession' , undefined ) ;
963+
964+ if ( sessionInvalid ) {
965+ req . log . warn ( 'BetterAuth session cookie present but session invalid' ) ;
966+ setCookie ( req , res , 'authSession' , undefined ) ;
967+ }
958968 }
959969
960970 if ( req . userId && req . accessToken ?. expiresIn ) {
0 commit comments