diff --git a/backend/app/Controllers/SallaController.php b/backend/app/Controllers/SallaController.php index 06ef2e9..eaebcda 100644 --- a/backend/app/Controllers/SallaController.php +++ b/backend/app/Controllers/SallaController.php @@ -36,7 +36,6 @@ class SallaController extends BaseController 'client_id' => $clientId, 'redirect_uri' => $redirectUri, 'response_type' => 'code', - 'scope' => 'read_orders read_customers', 'state' => $companyId ]); @@ -50,6 +49,16 @@ class SallaController extends BaseController */ public function callback(Request $request, Response $response) { + // Handle Salla returning an error redirect (e.g. invalid_scope, access_denied) + if (!empty($_GET['error'])) { + $errorCode = $_GET['error'] ?? 'unknown_error'; + $errorDesc = $_GET['error_description'] ?? 'An unknown error occurred during Salla authorization.'; + error_log("[Salla OAuth Error] $errorCode: $errorDesc"); + $appUrl = rtrim(getenv('APP_URL') ?: 'https://nabeh.intaleqapp.com', '/'); + header("Location: {$appUrl}/?salla_connect=error&reason=" . urlencode($errorDesc)); + exit; + } + $code = $_GET['code'] ?? ''; $companyId = $_GET['state'] ?? ''; diff --git a/backend/public/index.html b/backend/public/index.html index 5585ebd..5022a1a 100644 --- a/backend/public/index.html +++ b/backend/public/index.html @@ -1603,6 +1603,12 @@ ? 'تم ربط متجر سلة بنجاح!' : 'Salla store connected successfully!'; window.history.replaceState({}, document.title, window.location.pathname); + } else if (urlParams.get('salla_connect') === 'error') { + const reason = urlParams.get('reason') || ''; + this.dashboardError = this.lang === 'ar' + ? 'فشل ربط متجر سلة: ' + reason + : 'Salla connection failed: ' + reason; + window.history.replaceState({}, document.title, window.location.pathname); } },