File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed
Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change 1+ import { supabase } from '@/lib/supabase' ;
12import apiClient from './apiClient' ;
23
34// Payment API base URL / 支付API基础URL
@@ -12,16 +13,22 @@ const paymentApiClient = apiClient.create({
1213} ) ;
1314
1415// Add auth interceptor for payment API / 为支付API添加认证拦截器
15- paymentApiClient . interceptors . request . use ( ( config ) => {
16- // Get user session from localStorage / 从localStorage获取用户会话
17- const sessionStr = localStorage . getItem ( 'userSession' ) ;
18- if ( sessionStr ) {
16+ paymentApiClient . interceptors . request . use ( async ( config ) => {
17+ const result = await supabase . auth . getSession ( ) ;
18+ const accessToken = result . data . session ?. access_token ;
19+ if ( accessToken ) {
1920 try {
20- // Parse session JSON and extract access token / 解析会话JSON并提取访问令牌
21- const session = JSON . parse ( sessionStr ) ;
22- if ( session . supabaseSession ?. access_token ) {
23- config . headers . Authorization = `Bearer ${ session . supabaseSession . access_token } ` ;
24- }
21+ config . headers . Authorization = `Bearer ${ accessToken } ` ;
22+ } catch ( error ) {
23+ console . error ( 'Error parsing user session:' , error ) ;
24+ }
25+ }
26+ return config ;
27+ } ) ;
28+
29+ // Payment API interfaces / 支付API接口定义
30+
31+ /**
2532 } catch (error) {
2633 console.error('Error parsing user session:', error);
2734 }
You can’t perform that action at this time.
0 commit comments