From 028bc2e2b3248c3f0bd380064c3e544245ca1308 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 14 Sep 2023 13:26:08 +0200 Subject: [PATCH 1/2] ref: move SessionUtils to TS --- src/libs/{SessionUtils.js => SessionUtils.ts} | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) rename src/libs/{SessionUtils.js => SessionUtils.ts} (79%) diff --git a/src/libs/SessionUtils.js b/src/libs/SessionUtils.ts similarity index 79% rename from src/libs/SessionUtils.js rename to src/libs/SessionUtils.ts index 7b1fc9f42d25..a916be2e95da 100644 --- a/src/libs/SessionUtils.js +++ b/src/libs/SessionUtils.ts @@ -1,16 +1,10 @@ import Onyx from 'react-native-onyx'; -import _ from 'underscore'; -import lodashGet from 'lodash/get'; import ONYXKEYS from '../ONYXKEYS'; /** * Determine if the transitioning user is logging in as a new user. - * - * @param {String} transitionURL - * @param {String} sessionEmail - * @returns {Boolean} */ -function isLoggingInAsNewUser(transitionURL, sessionEmail) { +function isLoggingInAsNewUser(transitionURL: string, sessionEmail: string): boolean { // The OldDot mobile app does not URL encode the parameters, but OldDot web // does. We don't want to deploy OldDot mobile again, so as a work around we // compare the session email to both the decoded and raw email from the transition link. @@ -27,22 +21,22 @@ function isLoggingInAsNewUser(transitionURL, sessionEmail) { // Capture the un-encoded text in the email param const emailParamRegex = /[?&]email=([^&]*)/g; const matches = emailParamRegex.exec(transitionURL); - const linkedEmail = lodashGet(matches, 1, null); + const linkedEmail = matches?.[1] ?? null; return linkedEmail !== sessionEmail; } -let loggedInDuringSession; +let loggedInDuringSession: boolean | undefined; // To tell if the user logged in during this session we will check the value of session.authToken once when the app's JS inits. When the user logs out // we can reset this flag so that it can be updated again. Onyx.connect({ key: ONYXKEYS.SESSION, callback: (session) => { - if (!_.isUndefined(loggedInDuringSession)) { + if (loggedInDuringSession !== undefined) { return; } - if (session && session.authToken) { + if (session?.authToken) { loggedInDuringSession = false; } else { loggedInDuringSession = true; @@ -54,9 +48,6 @@ function resetDidUserLogInDuringSession() { loggedInDuringSession = undefined; } -/** - * @returns {boolean} - */ function didUserLogInDuringSession() { return Boolean(loggedInDuringSession); } From 6e6127f03a37eda87e325dfcf399922757c59cec Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Fri, 15 Sep 2023 09:51:59 +0200 Subject: [PATCH 2/2] fix: resolved comments --- src/libs/SessionUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SessionUtils.ts b/src/libs/SessionUtils.ts index a916be2e95da..fcbc9a887fa9 100644 --- a/src/libs/SessionUtils.ts +++ b/src/libs/SessionUtils.ts @@ -32,7 +32,7 @@ let loggedInDuringSession: boolean | undefined; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (session) => { - if (loggedInDuringSession !== undefined) { + if (loggedInDuringSession) { return; }