Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/meteor/client/lib/cachedStores/CachedStoresManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IWithManageableCache } from './CachedStore';
import { getDdpSdk } from '../sdk/ddpSdk';

class CachedStoresManager {
private items = new Set<IWithManageableCache>();
Expand All @@ -16,6 +17,8 @@ class CachedStoresManager {

const instance = new CachedStoresManager();

getDdpSdk().account.onLogout(() => instance.clearAllCachesOnLogout());

export {
/** @deprecated */
instance as CachedStoresManager,
Expand Down
8 changes: 5 additions & 3 deletions apps/meteor/client/lib/sdk/ddpSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Meteor } from 'meteor/meteor';

import { createMeteorBackedSdk } from './meteorBackedSdk';
import { isSdkTransportEnabled } from './sdkTransportEnabled';
import { STORAGE_KEYS, getStoredItem } from './storage';
import { STORAGE_KEYS, getStoredItem, removeStoredItem } from './storage';
import { userIdStore } from '../user';

const sdkTransportEnabled = isSdkTransportEnabled();
Expand Down Expand Up @@ -142,8 +142,10 @@ export const ensureConnectedAndAuthenticated = async (): Promise<void> => {
// latter dispatches a `logout` method which itself races against
// parallel re-auth flows in CI's parallel-shard environment and
// kicked otherwise-healthy tests out.
Accounts._unstoreLoginToken();
Meteor.connection.setUserId(null);
removeStoredItem(STORAGE_KEYS.USER_ID);
removeStoredItem(STORAGE_KEYS.LOGIN_TOKEN);
removeStoredItem(STORAGE_KEYS.LOGIN_TOKEN_EXPIRES);
(Meteor.connection as unknown as { setUserId: (uid: string | null) => void }).setUserId(null);
return;
}
console.warn('[ddpSdk] loginWithToken failed', error);
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/client/lib/sdk/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export const STORAGE_KEYS = {
USER_ID: 'Meteor.userId',
LOGIN_TOKEN: 'Meteor.loginToken',
LOGIN_TOKEN_EXPIRES: 'Meteor.loginTokenExpires',
E2EE_PUBLIC_KEY: 'public_key',
E2EE_PRIVATE_KEY: 'private_key',
E2EE_RANDOM_PASSWORD: 'e2e.randomPassword',
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/client/meteor/overrides/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ import './desktopInjection';
import './oauthRedirectUri';
import './settings';
import './totpOnCall';
import './unstoreLoginToken';
import './userAndUsers';
9 changes: 0 additions & 9 deletions apps/meteor/client/meteor/overrides/unstoreLoginToken.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useLDAPAndCrowdCollisionWarning } from './hooks/useLDAPAndCrowdCollisio
import { capitalize as capitalizeService } from '../../../lib/utils/stringUtils';
import { useReactiveValue } from '../../hooks/useReactiveValue';
import { loginServices } from '../../lib/loginServices';
import { getDdpSdk } from '../../lib/sdk/ddpSdk';
import { STORAGE_KEYS, removeStoredItem } from '../../lib/sdk/storage';

export type LoginMethods = keyof typeof Meteor extends infer T ? (T extends `loginWith${string}` ? T : never) : never;

Expand Down Expand Up @@ -125,27 +127,16 @@ const AuthenticationProvider = ({ children }: AuthenticationProviderProps): Reac
}),
getLoginToken: () => Accounts.storageLocation.getItem(Accounts.LOGIN_TOKEN_KEY) ?? null,
wipeLocalAuth: () => {
try {
Accounts._unstoreLoginToken();
} catch {
// ignore
}
removeStoredItem(STORAGE_KEYS.USER_ID);
removeStoredItem(STORAGE_KEYS.LOGIN_TOKEN);
removeStoredItem(STORAGE_KEYS.LOGIN_TOKEN_EXPIRES);
try {
Meteor.connection.setUserId(null);
} catch {
// ignore
}
},
unstoreLoginToken: (callback) => {
const { _unstoreLoginToken } = Accounts;
Accounts._unstoreLoginToken = function (...args) {
callback();
_unstoreLoginToken.apply(Accounts, args);
};
return () => {
Accounts._unstoreLoginToken = _unstoreLoginToken;
};
},
unstoreLoginToken: (callback) => getDdpSdk().account.onLogout(callback),
queryLoginServices: {
getCurrentValue: () => loginServices.getLoginServiceButtons(),
subscribe: (onStoreChange: () => void) => loginServices.on('changed', onStoreChange),
Expand Down
Loading