Skip to content

Commit 1b9d3c1

Browse files
committed
fix: try fix team workspace authentication issue
#230
1 parent 84b2d9f commit 1b9d3c1

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

src/api.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,29 @@ type ApiFileDownload = {
255255
error_message: string | null
256256
}
257257

258+
// eslint-disable-next-line no-restricted-syntax
259+
const enum ChatGPTCookie {
260+
AgeVerification = 'oai-av-seen',
261+
AllowNonessential = 'oai-allow-ne',
262+
DeviceId = 'oai-did',
263+
DomainMigrationSourceCompleted = 'oai-dm-src-c-240329',
264+
DomainMigrationTargetCompleted = 'oai-dm-tgt-c-240329',
265+
HasClickedOnTryItFirstLink = 'oai-tif-20240402',
266+
HasLoggedInBefore = 'oai-hlib',
267+
HideLoggedOutBanner = 'hide-logged-out-banner',
268+
IntercomDeviceIdDev = 'intercom-device-id-izw1u7l7',
269+
IntercomDeviceIdProd = 'intercom-device-id-dgkjq2bp',
270+
IpOverride = 'oai-ip-country',
271+
IsEmployee = '_oaiauth',
272+
IsPaidUser = '_puid',
273+
LastLocation = 'oai-ll',
274+
SegmentUserId = 'ajs_user_id',
275+
SegmentUserTraits = 'ajs_user_traits',
276+
ShowPaymentModal = 'ui-show-payment-modal',
277+
TempEnableUnauthedCompliance = 'temp-oai-compliance',
278+
Workspace = '_account',
279+
}
280+
258281
const sessionApi = urlcat(baseUrl, '/api/auth/session')
259282
const conversationApi = (id: string) => urlcat(apiUrl, '/conversation/:id', { id })
260283
const conversationsApi = (offset: number, limit: number) => urlcat(apiUrl, '/conversations', { offset, limit })
@@ -448,14 +471,19 @@ async function _fetchAccountsCheck(): Promise<ApiAccountsCheck> {
448471

449472
const fetchAccountsCheck = memorize(_fetchAccountsCheck)
450473

474+
const getCookie = (key: string) => document.cookie.match(`(^|;)\\s*${key}\\s*=\\s*([^;]+)`)?.pop() || ''
475+
451476
export async function getTeamAccountId(): Promise<string | null> {
452477
const accountsCheck = await fetchAccountsCheck()
453-
const accountKey = accountsCheck.account_ordering?.[0] || 'default'
454-
const account = accountsCheck.accounts[accountKey]
455-
if (!account) return null
456-
if (account.account.plan_type !== 'team') return null
478+
const workspaceId = getCookie(ChatGPTCookie.Workspace)
479+
if (workspaceId) {
480+
const account = accountsCheck.accounts[workspaceId]
481+
if (account) {
482+
return account.account.account_id
483+
}
484+
}
457485

458-
return account.account.account_id
486+
return null
459487
}
460488

461489
export interface ConversationResult {

0 commit comments

Comments
 (0)