Apply Laravel 5.7 MustVerifyEmail on Multiple Authentication System

后端 未结 4 1122
清歌不尽
清歌不尽 2021-01-07 01:31

I\'m trying to apply Laravel-5.7 MustVerifyEmail on multiple authentication system. So far what I\'ve done is as follows:

  1. created verification routes for the \
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-07 02:13

    Finally, after four days of research I was able to solve the issue.

    I altered the "EnsureEmailIsVerified" middleware as follows:

    check()) {
    
                    if (! Auth::guard($guard)->user() ||
                        (Auth::guard($guard)->user() instanceof MustVerifyEmail &&
                        ! Auth::guard($guard)->user()->hasVerifiedEmail())) {
                        return $request->expectsJson()
                                ? abort(403, 'Your email address is not verified.')
                                : Redirect::route('admin.verification.notice');
                    }  
    
                }
    
            }
    
            elseif ($guard == 'auditor') {
    
                if (Auth::guard($guard)->check()) {
    
                    if (! Auth::guard($guard)->user() ||
                        (Auth::guard($guard)->user() instanceof MustVerifyEmail &&
                        ! Auth::guard($guard)->user()->hasVerifiedEmail())) {
                        return $request->expectsJson()
                                ? abort(403, 'Your email address is not verified.')
                                : Redirect::route('auditor.verification.notice');
                    }  
    
                }
    
            }
    
            elseif ($guard == 'web') {
    
                if (Auth::guard($guard)->check()) {
    
                    if (! Auth::guard($guard)->user() ||
                        (Auth::guard($guard)->user() instanceof MustVerifyEmail &&
                        ! Auth::guard($guard)->user()->hasVerifiedEmail())) {
                        return $request->expectsJson()
                                ? abort(403, 'Your email address is not verified.')
                                : Redirect::route('verification.notice');
                        }  
    
                    }
                }
    
            }
    
            return $next($request);
        }
    }
    

    And that's solved my problem.

提交回复
热议问题