@@ -919,6 +919,9 @@ export const getBootData = async (
919919 middleware ?: BootMiddleware ,
920920) : Promise < AnonymousBoot | LoggedInBoot > => {
921921 const referrer = getBootReferrer ( req ) ;
922+ const shouldRefreshJwt =
923+ ! req . accessToken ?. expiresIn ||
924+ differenceInMinutes ( req . accessToken . expiresIn , new Date ( ) ) <= 3 ;
922925
923926 const baSessionCookie = req . cookies [ cookies . authSession . key ] ;
924927 if ( baSessionCookie ) {
@@ -933,14 +936,11 @@ export const getBootData = async (
933936 req . userId = session . user . id ;
934937 req . trackingId = req . userId ;
935938 setTrackingId ( req , res , req . trackingId ) ;
936- const jwtValid =
937- req . accessToken ?. expiresIn &&
938- differenceInMinutes ( req . accessToken . expiresIn , new Date ( ) ) > 3 ;
939939 return loggedInBoot ( {
940940 con,
941941 req,
942942 res,
943- refreshToken : ! jwtValid ,
943+ refreshToken : shouldRefreshJwt ,
944944 middleware,
945945 userId : req . userId ,
946946 } ) ;
@@ -957,16 +957,12 @@ export const getBootData = async (
957957 setCookie ( req , res , 'authSession' , undefined ) ;
958958 }
959959
960- if (
961- req . userId &&
962- req . accessToken ?. expiresIn &&
963- differenceInMinutes ( req . accessToken ?. expiresIn , new Date ( ) ) > 3
964- ) {
960+ if ( req . userId && req . accessToken ?. expiresIn ) {
965961 return loggedInBoot ( {
966962 con,
967963 req,
968964 res,
969- refreshToken : false ,
965+ refreshToken : shouldRefreshJwt ,
970966 middleware,
971967 userId : req . userId ,
972968 } ) ;
0 commit comments