aboutsummaryrefslogtreecommitdiff
path: root/apps/browser-extension/utils/api.ts
diff options
context:
space:
mode:
authorMaheshtheDev <[email protected]>2025-09-24 21:02:05 +0000
committerMaheshtheDev <[email protected]>2025-09-24 21:02:05 +0000
commit7e8b65b36dce243babeefe27ef1739cb4c495beb (patch)
treeab0276e15d84398e92dc9a39071a6ecd0645175f /apps/browser-extension/utils/api.ts
parentfix(pricing): update the new pricing limits on pro plan (#439) (diff)
downloadsupermemory-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 ![image.png](https://app.graphite.dev/user-attachments/assets/b751f6a4-1a33-42d1-88dd-61aff55dd1c7.png)![image.png](https://app.graphite.dev/user-attachments/assets/202f69f9-c853-4801-850e-ee6d115e300c.png)
Diffstat (limited to 'apps/browser-extension/utils/api.ts')
-rw-r--r--apps/browser-extension/utils/api.ts29
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> {