Fix API URL construction in apiRequest function

- Add API_BASE_URL prefix to fetch calls in the second apiRequest function
- Fix wallet endpoint URLs to not double-prefix /api
- This fixes the 401 errors and redirect loop
parent 784653d0
......@@ -1443,7 +1443,7 @@ let walletData = null;
*/
async function getWallet() {
try {
const response = await apiRequest('/api/wallet');
const response = await apiRequest('/wallet');
if (response.success) {
walletData = response.wallet;
updateWalletDisplay();
......@@ -1498,7 +1498,7 @@ function updateWalletDisplay() {
*/
async function depositToWallet(amount, paymentGateway = null, paymentReference = null, description = null) {
try {
const response = await apiRequest('/api/wallet/deposit', 'POST', {
const response = await apiRequest('/wallet/deposit', 'POST', {
amount: parseFloat(amount),
payment_gateway: paymentGateway,
payment_reference: paymentReference,
......@@ -1526,7 +1526,7 @@ async function depositToWallet(amount, paymentGateway = null, paymentReference =
*/
async function withdrawFromWallet(amount, description = null) {
try {
const response = await apiRequest('/api/wallet/withdraw', 'POST', {
const response = await apiRequest('/wallet/withdraw', 'POST', {
amount: parseFloat(amount),
description: description
});
......@@ -1552,7 +1552,7 @@ async function withdrawFromWallet(amount, description = null) {
*/
async function getWalletTransactions(limit = 20, offset = 0, transactionType = null) {
try {
let url = `/api/wallet/transactions?limit=${limit}&offset=${offset}`;
let url = `/wallet/transactions?limit=${limit}&offset=${offset}`;
if (transactionType) {
url += `&transaction_type=${transactionType}`;
}
......@@ -1764,7 +1764,7 @@ async function apiRequest(endpoint, method = 'GET', data = null) {
}
try {
const response = await fetch(endpoint, options);
const response = await fetch(`${API_BASE_URL}${endpoint}`, options);
const result = await response.json();
// Handle token expiration
......@@ -1774,7 +1774,7 @@ async function apiRequest(endpoint, method = 'GET', data = null) {
if (refreshed) {
// Retry the request
options.headers['Authorization'] = `Bearer ${localStorage.getItem('authToken')}`;
const retryResponse = await fetch(endpoint, options);
const retryResponse = await fetch(`${API_BASE_URL}${endpoint}`, options);
return await retryResponse.json();
} else {
// Redirect to login
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment