Skip to content

Commit

Permalink
authenticate middleware redirect to default login page issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisheksarmah committed Aug 5, 2020
1 parent 5da2e9b commit 9626f93
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
// Contact us
Route::post('/contact', 'ContactController@store')->name('contact.store')->middleware(\Spatie\Honeypot\ProtectAgainstSpam::class);

Route::group(['middleware' => 'auth'], function () {
Route::group(['middleware' => 'auth.flowcms'], function () {
// Dashboard
Route::get('/dashboard', 'DashboardController@index')->name('dashboard');

Expand Down
11 changes: 4 additions & 7 deletions src/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Flowcms\Flowcms\Controllers\Auth;

use Illuminate\Routing\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
Expand All @@ -21,12 +20,10 @@ class LoginController extends Controller

use AuthenticatesUsers;

/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/dashboard';
public function redirectTo()
{
return route('flowcms::dashboard');
}

/**
* Create a new controller instance.
Expand Down
2 changes: 2 additions & 0 deletions src/FlowcmsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
use Flowcms\Flowcms\Middleware\HtmlMinifier;
use Flowcms\Flowcms\Middleware\AuthenticateWithFlowcms;

class FlowcmsServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -49,6 +50,7 @@ public function boot(Router $router)
* Optional methods to load your package assets
*/
$router->middlewareGroup('HtmlMinifier', [HtmlMinifier::class]);
$router->middlewareGroup('auth.flowcms', [AuthenticateWithFlowcms::class]);

$this->loadViewsFrom(__DIR__ . '/../resources/views', 'flowcms');
$this->loadBladeDirectives();
Expand Down
21 changes: 21 additions & 0 deletions src/Middleware/AuthenticateWithFlowcms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Flowcms\Flowcms\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;

class AuthenticateWithFlowcms extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (!$request->expectsJson()) {
return route('flowcms::login');
}
}
}

0 comments on commit 9626f93

Please sign in to comment.