diff options
| author | MaheshtheDev <[email protected]> | 2025-09-24 21:02:05 +0000 |
|---|---|---|
| committer | MaheshtheDev <[email protected]> | 2025-09-24 21:02:05 +0000 |
| commit | 7e8b65b36dce243babeefe27ef1739cb4c495beb (patch) | |
| tree | ab0276e15d84398e92dc9a39071a6ecd0645175f /apps/browser-extension/utils/api.ts | |
| parent | fix(pricing): update the new pricing limits on pro plan (#439) (diff) | |
| download | supermemory-7e8b65b36dce243babeefe27ef1739cb4c495beb.tar.xz supermemory-7e8b65b36dce243babeefe27ef1739cb4c495beb.zip | |
feat(extension): Auto Logout when token is invalidated, Account Section (#438)
## Changes:
- Added token validation logic that checks if the current auth token is still valid
- Implemented automatic logout when token is invalidated with appropriate user feedback
- Added an Account section in the popup that displays the user's email
- Improved error toast messages with clearer formatting and helper text

Diffstat (limited to 'apps/browser-extension/utils/api.ts')
| -rw-r--r-- | apps/browser-extension/utils/api.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/apps/browser-extension/utils/api.ts b/apps/browser-extension/utils/api.ts index 2a4c838b..d98b39f5 100644 --- a/apps/browser-extension/utils/api.ts +++ b/apps/browser-extension/utils/api.ts @@ -100,6 +100,35 @@ export async function setDefaultProject(project: Project): Promise<void> { } /** + * Validate if current bearer token is still valid + */ +export async function validateAuthToken(): Promise<boolean> { + try { + await makeAuthenticatedRequest<ProjectsResponse>("/v3/projects") + return true + } catch (error) { + if (error instanceof AuthenticationError) { + return false + } + console.error("Failed to validate auth token:", error) + return true + } +} + +/** + * Get user data from storage + */ +export async function getUserData(): Promise<{ email?: string } | null> { + try { + const result = await chrome.storage.local.get([STORAGE_KEYS.USER_DATA]) + return result[STORAGE_KEYS.USER_DATA] || null + } catch (error) { + console.error("Failed to get user data:", error) + return null + } +} + +/** * Save memory to Supermemory API */ export async function saveMemory(payload: MemoryPayload): Promise<unknown> { |