1import JsonFile from '@expo/json-file';
2
3import { getStateJsonPath } from './paths';
4
5// copied from https://github.com/expo/eas-cli/blob/f0c958e58bc7aa90ee8f822e075d40703563708e/packages/eas-cli/src/user/sessionStorage.ts
6
7type UserSettingsData = {
8  auth?: SessionData;
9};
10
11type SessionData = {
12  sessionSecret: string;
13
14  // These fields are potentially used by Expo CLI.
15  userId: string;
16  username: string;
17  currentConnection: 'Username-Password-Authentication';
18};
19
20export function getSession(): SessionData | null {
21  try {
22    return JsonFile.read<UserSettingsData>(getStateJsonPath())?.auth ?? null;
23  } catch (error: any) {
24    if (error.code === 'ENOENT') {
25      return null;
26    }
27    throw error;
28  }
29}
30