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

Comments

Projects
None yet
3 participants
@ryanmortier
Copy link

commented Dec 13, 2018

  • 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

This comment has been minimized.

Copy link
Member

commented Dec 13, 2018

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

This comment has been minimized.

Copy link
Author

commented Dec 13, 2018

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

This comment has been minimized.

Copy link
Member

commented Dec 13, 2018

Can you post your User model?

@ryanmortier

This comment has been minimized.

Copy link
Author

commented Dec 13, 2018

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

This comment has been minimized.

Copy link
Author

commented Dec 13, 2018

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

@driesvints

This comment has been minimized.

Copy link
Member

commented Dec 13, 2018

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

That should do it.

@driesvints driesvints closed this Dec 13, 2018

@ryanmortier

This comment has been minimized.

Copy link
Author

commented Dec 13, 2018

Oops, sorry for wasting your time.

@kelvinthiongo

This comment has been minimized.

Copy link

commented Apr 9, 2019

@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
You can’t perform that action at this time.