feat: add customer token support to API client
Extended path-based token selection to include customer tokens: - /shop/* routes now use customer_token - Fallback order: admin_token || vendor_token || customer_token This ensures the correct token is used when logged into multiple portals (admin, vendor, customer) simultaneously. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -37,11 +37,13 @@ class APIClient {
|
|||||||
* Uses path-based detection to return the correct token:
|
* Uses path-based detection to return the correct token:
|
||||||
* - /admin/* routes use admin_token
|
* - /admin/* routes use admin_token
|
||||||
* - /vendor/* routes use vendor_token
|
* - /vendor/* routes use vendor_token
|
||||||
* - Other routes fall back to admin_token || vendor_token
|
* - /shop/* routes use customer_token
|
||||||
|
* - Other routes fall back to admin_token || vendor_token || customer_token
|
||||||
*/
|
*/
|
||||||
getToken() {
|
getToken() {
|
||||||
const adminToken = localStorage.getItem('admin_token');
|
const adminToken = localStorage.getItem('admin_token');
|
||||||
const vendorToken = localStorage.getItem('vendor_token');
|
const vendorToken = localStorage.getItem('vendor_token');
|
||||||
|
const customerToken = localStorage.getItem('customer_token');
|
||||||
const currentPath = window.location.pathname;
|
const currentPath = window.location.pathname;
|
||||||
|
|
||||||
let token;
|
let token;
|
||||||
@@ -54,15 +56,20 @@ class APIClient {
|
|||||||
} else if (currentPath.startsWith('/admin/') || currentPath.startsWith('/api/v1/admin/')) {
|
} else if (currentPath.startsWith('/admin/') || currentPath.startsWith('/api/v1/admin/')) {
|
||||||
token = adminToken;
|
token = adminToken;
|
||||||
source = 'admin (path-based)';
|
source = 'admin (path-based)';
|
||||||
|
} else if (currentPath.includes('/shop/') || currentPath.startsWith('/api/v1/shop/')) {
|
||||||
|
token = customerToken;
|
||||||
|
source = 'customer (path-based)';
|
||||||
} else {
|
} else {
|
||||||
// Default fallback for other paths
|
// Default fallback for other paths
|
||||||
token = adminToken || vendorToken;
|
token = adminToken || vendorToken || customerToken;
|
||||||
source = token === adminToken ? 'admin (fallback)' : 'vendor (fallback)';
|
source = token === adminToken ? 'admin (fallback)' :
|
||||||
|
token === vendorToken ? 'vendor (fallback)' : 'customer (fallback)';
|
||||||
}
|
}
|
||||||
|
|
||||||
apiLog.debug('Getting token:', {
|
apiLog.debug('Getting token:', {
|
||||||
hasAdminToken: !!adminToken,
|
hasAdminToken: !!adminToken,
|
||||||
hasVendorToken: !!vendorToken,
|
hasVendorToken: !!vendorToken,
|
||||||
|
hasCustomerToken: !!customerToken,
|
||||||
currentPath,
|
currentPath,
|
||||||
source,
|
source,
|
||||||
usingToken: token ? source : 'none'
|
usingToken: token ? source : 'none'
|
||||||
|
|||||||
Reference in New Issue
Block a user