Skip to content
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

'verified' middleware does not work with 'auth' middleware? #26843

Closed
ryanmortier opened this issue Dec 13, 2018 · 8 comments
Closed

'verified' middleware does not work with 'auth' middleware? #26843

ryanmortier opened this issue Dec 13, 2018 · 8 comments

Comments

@ryanmortier
Copy link

  • Laravel Version: 5.7.17 (latest)
  • PHP Version: 7.2.13
  • Database Driver & Version: MySQL 5.7

Description:

When adding ->middleware(['auth', 'verified']) to a route, the verified middleware doesn't apply.

Steps To Reproduce:

  • laravel new blog
  • php artisan make:auth
  • Create database and modify .env file
  • php artisan migrate
  • php artisan tinker then:
\App\User::create([
    'name' => 'Test User',
    'email' => 'test@example.com',
    'password' => bcrypt('secret'),
]);
  • Add $this->middleware(['auth', 'verified']); to the HomeController constructor
  • Login and the home view is still shown even though you haven't verified the email address.
@driesvints
Copy link
Member

It's normal that your login view is still shown as this is controlled by the LoginController and not the HomeController. You're sure you're not mixing up the "welcome" view and "home" view?

@ryanmortier
Copy link
Author

It's definitely not the welcome view. It's specifically the resources/views/home.blade.php view, the one that says "You are logged in!" and is presented in the HomeController index method, the same controller that has both those middleware attached.

@driesvints
Copy link
Member

Can you post your User model?

@ryanmortier
Copy link
Author

Since this is a fresh install it's the default:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

@ryanmortier
Copy link
Author

Are you able to reproduce the issue? It should only take 30 seconds.

@driesvints
Copy link
Member

You need to implement the MustVerifyEmail interface: https://laravel.com/docs/5.7/verification#introduction

That should do it.

@ryanmortier
Copy link
Author

Oops, sorry for wasting your time.

@kelvinthiongo
Copy link

@ryanmortier infact you didn't waste our tym, very many people forget this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants