Browse Source

fix: correct session token parsing in API calls #16

Fixed 401 (Unauthorized) errors by correcting session data structure
access in all frontend components.

The session data stored in localStorage has structure:
{ success: true, session: { access_token: "..." } }

Changed from: session.access_token
Changed to: session.session.access_token

Files fixed:
- IntegrationsContent.tsx (lines 50, 185)
- DashboardContext.tsx (line 47)
- WooCommerceConnect.tsx (line 72)
- ShopifyConnect.tsx (line 72)
- ShopRenterConnect.tsx (line 61)
- RecentCallsTable.tsx (line 51)

This resolves deployment authentication issues when accessing
Supabase Edge Functions from the production build.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude 5 months ago
parent
commit
f4b5a2f6ca

+ 2 - 2
shopcall.ai-main/src/components/IntegrationsContent.tsx

@@ -47,7 +47,7 @@ export function IntegrationsContent() {
       const session = JSON.parse(sessionData);
       const response = await fetch(`${API_URL}/api/stores`, {
         headers: {
-          'Authorization': `Bearer ${session.access_token}`,
+          'Authorization': `Bearer ${session.session.access_token}`,
           'Content-Type': 'application/json'
         }
       });
@@ -182,7 +182,7 @@ export function IntegrationsContent() {
       const response = await fetch(`${API_URL}/api/stores/${storeId}`, {
         method: 'DELETE',
         headers: {
-          'Authorization': `Bearer ${session.access_token}`,
+          'Authorization': `Bearer ${session.session.access_token}`,
           'Content-Type': 'application/json'
         }
       });

+ 1 - 1
shopcall.ai-main/src/components/RecentCallsTable.tsx

@@ -48,7 +48,7 @@ export function RecentCallsTable() {
         const session = JSON.parse(sessionData);
         const response = await fetch(`${API_URL}/api/call-logs`, {
           headers: {
-            'Authorization': `Bearer ${session.access_token}`,
+            'Authorization': `Bearer ${session.session.access_token}`,
             'Content-Type': 'application/json'
           }
         });

+ 1 - 1
shopcall.ai-main/src/components/ShopRenterConnect.tsx

@@ -58,7 +58,7 @@ export function ShopRenterConnect({ onClose }: ShopRenterConnectProps) {
       const response = await fetch(`${API_URL}/oauth-shoprenter-init?shopname=${shopname}`, {
         method: 'GET',
         headers: {
-          'Authorization': `Bearer ${session.access_token}`,
+          'Authorization': `Bearer ${session.session.access_token}`,
           'Content-Type': 'application/json'
         }
       });

+ 1 - 1
shopcall.ai-main/src/components/ShopifyConnect.tsx

@@ -69,7 +69,7 @@ export function ShopifyConnect({ onClose }: ShopifyConnectProps) {
         {
           method: 'GET',
           headers: {
-            'Authorization': `Bearer ${session.access_token}`,
+            'Authorization': `Bearer ${session.session.access_token}`,
             'Content-Type': 'application/json'
           }
         }

+ 1 - 1
shopcall.ai-main/src/components/WooCommerceConnect.tsx

@@ -69,7 +69,7 @@ export function WooCommerceConnect({ onClose }: WooCommerceConnectProps) {
         {
           method: 'GET',
           headers: {
-            'Authorization': `Bearer ${session.access_token}`,
+            'Authorization': `Bearer ${session.session.access_token}`,
             'Content-Type': 'application/json'
           }
         }

+ 1 - 1
shopcall.ai-main/src/components/context/DashboardContext.tsx

@@ -44,7 +44,7 @@ export function DashboardProvider({ children }: { children: ReactNode }) {
       const session = JSON.parse(sessionData);
       const response = await fetch(`${API_URL}/api/dashboard/stats`, {
         headers: {
-          'Authorization': `Bearer ${session.access_token}`,
+          'Authorization': `Bearer ${session.session.access_token}`,
           'Content-Type': 'application/json'
         }
       });