-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
routing issue #50
Comments
I'm using both the native Laravel auth and hesto's multi-auth. Would this work for me? |
Add these lines to your // This is a workaround
if ($request->is('admin/*')) {
return redirect()->guest('/admin/login');
} Above lines should come before |
I want to explain my opinion . app/Http/Middleware/RedirectIfNotAdmin.php
|
Difference between 'middleware' => ['web', 'admin', 'auth:admin'] and 'middleware' => ['web', 'admin']
Add Exception to Debug
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
+ throw new \Exception("forDebug", 1);
return redirect()->guest('login');
}
public function handle($request, Closure $next, $guard = 'admin')
{
if (!Auth::guard($guard)->check()) {
+ throw new \Exception("forDebug", 1);
return redirect('admin/login');
}
return $next($request);
} Compare information of debug, find out the division of runtime
protected function getSlice()
{
return function ($stack, $pipe) {
return function ($passable) use ($stack, $pipe) {
try {
$slice = parent::getSlice();
$callable = $slice($stack, $pipe);
return $callable($passable); //line 33
} catch (Exception $e) {
return $this->handleException($passable, $e); //line 35
} catch (Throwable $e) {
return $this->handleException($passable, new FatalThrowableError($e));
}
};
};
} |
@han-huang
Don't know if this is correct way. @Hesto PS: This issue is related to #29 |
I think it is ok. Or you can use Auth::guard('admin')->user()->email . |
In other not for your changes to interfere with other packages such as Bouncer its will be better to edit you your Authenticate class in namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function redirectTo($request)
{
if ($request->is('admin/*')) {
return route('admin.login');
}
return route('login');
}
} Thanks you ! |
this fix worked for me
changed the middleware
so any route use the middleware |
I found a routing issue.
e.g. http://domain.app:8016/admin/home (not login yet) -> http://domain.app:8016/login
The correct redirecting url is /admin/login , not /login.
I modify the following code. It can redirect correct url and fix auth.blade.php.
app/Providers/RouteServiceProvider.php
resources/views/admin/layout/auth.blade.php
I hope this is useful.
The text was updated successfully, but these errors were encountered: