Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/libs/Firebase/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import crashlytics from '@react-native-firebase/crashlytics';
import perf from '@react-native-firebase/perf';
import * as Environment from '@libs/Environment/Environment';
import * as SessionUtils from '@libs/SessionUtils';
import type {Log, StartTrace, StopTrace, TraceMap} from './types';

const traceMap: TraceMap = {};
Expand All @@ -16,9 +17,12 @@ const startTrace: StartTrace = (customEventName) => {
return;
}

const session = SessionUtils.getSession();

perf()
.startTrace(customEventName)
.then((trace) => {
trace.putAttribute('accountID', session?.accountID?.toString() ?? 'N/A');
traceMap[customEventName] = {
trace,
start,
Expand Down
10 changes: 9 additions & 1 deletion src/libs/SessionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';

/**
* Determine if the transitioning user is logging in as a new user.
Expand All @@ -26,12 +28,14 @@ function isLoggingInAsNewUser(transitionURL?: string, sessionEmail?: string): bo
}

let loggedInDuringSession: boolean | undefined;
let currentSession: OnyxEntry<OnyxTypes.Session>;

// 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) => {
currentSession = session;
if (loggedInDuringSession) {
return;
}
Expand All @@ -53,4 +57,8 @@ function didUserLogInDuringSession() {
return !!loggedInDuringSession;
}

export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession};
function getSession() {
return currentSession;
}

export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession, getSession};