Skip to content

Commit dcc5608

Browse files
fix: ios logout issues (#3794)
Co-authored-by: Ido Shamun <1993245+idoshamun@users.noreply.github.com>
1 parent 4cdce4c commit dcc5608

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

__tests__/routes/betterAuth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('betterAuth routes', () => {
6565
modelName: 'ba_session',
6666
storeSessionInDatabase: true,
6767
expiresIn: 30 * 24 * 60 * 60,
68-
updateAge: 24 * 60 * 60,
68+
updateAge: 12 * 60 * 60,
6969
});
7070
});
7171

src/betterAuth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { triggerTypedEvent } from './common/typedPubsub';
1212
import { sendEmail, CioTransactionalMessageTemplateId } from './common/mailing';
1313
import { handleRegex } from './common/object';
1414
import { validateAndTransformHandle } from './common/handles';
15-
import { ONE_DAY_IN_SECONDS, ONE_MONTH_IN_SECONDS } from './common/constants';
15+
import { ONE_MONTH_IN_SECONDS, ONE_HOUR_IN_SECONDS } from './common/constants';
1616
import { singleRedisClient } from './redis';
1717
import { User } from './entity/user/User';
1818
import { cookies, extractRootDomain } from './cookies';
@@ -399,7 +399,7 @@ export const getBetterAuthOptions = (pool: Pool): BetterAuthOptions => {
399399
modelName: 'ba_session',
400400
storeSessionInDatabase: true,
401401
expiresIn: ONE_MONTH_IN_SECONDS,
402-
updateAge: ONE_DAY_IN_SECONDS,
402+
updateAge: 12 * ONE_HOUR_IN_SECONDS,
403403
},
404404
account: {
405405
modelName: 'ba_account',

src/routes/boot.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import {
9393
} from '../common/profile/completion';
9494
import { getUnreadNotificationsCount } from '../notifications/common';
9595
import { unwrapArray } from '../common/array';
96+
import { asyncRetry } from '../integrations/retry';
9697

9798
export 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

Comments
 (0)