Skip to content
Merged
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
34 changes: 15 additions & 19 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,20 @@

const INVALID_TOKEN = 'pizza';

let deprecatedSession: Session = {};
let session: Session = {};
let authPromiseResolver: ((value: boolean) => void) | null = null;

let isHybridAppSetupFinished = false;
let hasSwitchedAccountInHybridMode = false;

Onyx.connectWithoutView({
Onyx.connect({

Check warning on line 80 in src/libs/actions/Session/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
const session = value ?? {};
deprecatedSession = value ?? {};
session = value ?? {};

if (!session.creationDate) {
session.creationDate = new Date().getTime();
}
if (session.authToken && authPromiseResolver) {
authPromiseResolver(true);
authPromiseResolver = null;
Expand All @@ -100,25 +102,25 @@
});

let stashedSession: Session = {};
Onyx.connect({

Check warning on line 105 in src/libs/actions/Session/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.STASHED_SESSION,
callback: (value) => (stashedSession = value ?? {}),
});

let credentials: Credentials = {};
Onyx.connect({

Check warning on line 111 in src/libs/actions/Session/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CREDENTIALS,
callback: (value) => (credentials = value ?? {}),
});

let stashedCredentials: Credentials = {};
Onyx.connect({

Check warning on line 117 in src/libs/actions/Session/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.STASHED_CREDENTIALS,
callback: (value) => (stashedCredentials = value ?? {}),
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 123 in src/libs/actions/Session/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (newActivePolicyID) => {
activePolicyID = newActivePolicyID;
Expand All @@ -126,7 +128,7 @@
});

function isSupportAuthToken(): boolean {
return deprecatedSession.authTokenType === CONST.AUTH_TOKEN_TYPES.SUPPORT;
return session.authTokenType === CONST.AUTH_TOKEN_TYPES.SUPPORT;
}

/**
Expand Down Expand Up @@ -243,7 +245,7 @@
* Checks if the account is an anonymous account.
*/
function isAnonymousUser(sessionParam?: OnyxEntry<Session>): boolean {
return (sessionParam?.authTokenType ?? deprecatedSession.authTokenType) === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
return (sessionParam?.authTokenType ?? session.authTokenType) === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
}

function hasStashedSession(): boolean {
Expand All @@ -254,7 +256,7 @@
* Checks if the user has authToken
*/
function hasAuthToken(): boolean {
return !!deprecatedSession.authToken;
return !!session.authToken;
}

/**
Expand Down Expand Up @@ -321,10 +323,7 @@
if (!isSupportal && shouldStashSession) {
onyxSetParams = {
[ONYXKEYS.STASHED_CREDENTIALS]: credentials,
[ONYXKEYS.STASHED_SESSION]: {
...deprecatedSession,
creationDate: deprecatedSession.creationDate ?? new Date().getTime(),
},
[ONYXKEYS.STASHED_SESSION]: session,
};
}

Expand All @@ -347,7 +346,7 @@
authToken: stashedSession.authToken ?? '',
// eslint-disable-next-line rulesdir/no-default-id-values
policyID: activePolicyID ?? '',
accountID: deprecatedSession.accountID ? String(deprecatedSession.accountID) : '',
accountID: session.accountID ? String(session.accountID) : '',
});
hasSwitchedAccountInHybridMode = true;
}
Expand Down Expand Up @@ -531,8 +530,8 @@
*/
function buildOnyxDataToCleanUpAnonymousUser() {
const data: Record<string, null> = {};
if (deprecatedSession.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS && deprecatedSession.accountID) {
data[deprecatedSession.accountID] = null;
if (session.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS && session.accountID) {
data[session.accountID] = null;
}
return {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
Expand Down Expand Up @@ -620,10 +619,7 @@
const stashedData = hybridApp?.delegateAccessData?.isDelegateAccess
? {
[ONYXKEYS.STASHED_CREDENTIALS]: credentials,
[ONYXKEYS.STASHED_SESSION]: {
...deprecatedSession,
creationDate: deprecatedSession.creationDate ?? new Date().getTime(),
},
[ONYXKEYS.STASHED_SESSION]: session,
}
: {
[ONYXKEYS.STASHED_CREDENTIALS]: {},
Expand Down Expand Up @@ -1239,7 +1235,7 @@
*/
function waitForUserSignIn(): Promise<boolean> {
return new Promise<boolean>((resolve) => {
if (deprecatedSession.authToken) {
if (session.authToken) {
resolve(true);
} else {
authPromiseResolver = resolve;
Expand Down
Loading