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); }