Skip to content

Commit

Permalink
Update Module.php
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhirtz committed Apr 5, 2024
1 parent 8d2f88c commit 5f2e3a5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/modules/admin/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,20 @@ public function beforeAction($action): bool
{
$request = Yii::$app->getRequest();

if (!$request->getIsConsoleRequest()) {
if (Yii::$app->has('user')) {
Yii::$app->getUser()->loginUrl ??= ['/admin/account/login'];

if (!YII_DEBUG) {
Yii::$app->getErrorHandler()->errorView = '@skeleton/modules/admin/views/dashboard/error.php';
}
}

if (!$request->getIsConsoleRequest()) {
// Redirects draft URLs for the backend, but only if it's not an AJAX to prevent breaking frontend
// implementations or REST APIs that use admin endpoints.
if ($request->getIsDraft() && !$request->getIsAjax()) {
Yii::$app->getResponse()->redirect($request->getProductionHostInfo() . $request->getUrl())->send();
$url = $request->getProductionHostInfo() . $request->getUrl();
Yii::$app->getResponse()->redirect($url)->send();
}

if (count(Yii::$app->getI18n()->getLanguages()) > 1) {
Expand Down

0 comments on commit 5f2e3a5

Please sign in to comment.