0

So I used this preset for the authentication for my laravel app and it is sending me verification emails but I want to redirect them to a certain page telling them to verify their emails first before logging in but instead, it will automatically log them into my app without them verifying their email.

This is my code Homecontroller

 public function __construct()
{
    $this->middleware(['auth','verified']);
}

web.php

Auth::routes(['verify' => true]);

then my user model is this

    <?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable implements MustVerifyEmail
{
    use HasApiTokens, HasFactory, Notifiable;

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

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

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

I watch tutorials similar to mine and it works on them with the changes above but on my end it seems it's not working, it will directly go to my dashboard.

This is my database migration

 Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });

1 Answers1

0

you can by removing this in RegisteredUserController.php after event(new Registered($user)) :

Auth::login($user); // this function is responsible to user logged in  automatically to your website

and in your web.php file try this :

    Route::middleware(['auth', 'verified'])->group(function () {
    // your routes here exemeple :
    Route::get('/dashboard', function () {
        return view('dashboard');

       })->name('dashboard');
    });

instead of : Auth::routes(['verify' => true]);

i hope it was useful

Joukhar
  • 724
  • 1
  • 3
  • 18