| 67 | } |
| 68 | |
| 69 | export const getUserCredentials = (clientEnv: ClientEnv = env): User | null => { |
| 70 | const credentialsPath = getCredentialsPath(clientEnv) |
| 71 | if (!fs.existsSync(credentialsPath)) { |
| 72 | return null |
| 73 | } |
| 74 | |
| 75 | try { |
| 76 | const credentialsFile = fs.readFileSync(credentialsPath, 'utf8') |
| 77 | const user = userFromJson(credentialsFile) |
| 78 | return user || null |
| 79 | } catch (error) { |
| 80 | console.error('Error reading credentials', error) |
| 81 | return null |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * ChatGPT OAuth credentials stored in the credentials file. |