Class verified does not exist, Email verification Laravel 5.7 - php

I have updated my Laravel project from 5.6 to 5.7. Laravel 5.7 comes with the new email verification so I tried to build that in my new project.
I folowed the instructions on the update guide from the Laravel docs, but after registering a new user on my site, I receive the message: Class verified does not exist. It does send me an email, so that part works just fine. But I think I'm missing something in my middleware, because the docs say we have to add: Auth::routes(['verify' => true]); instead of the original Auth::routes();
Did anybode had the same problem like I did?

Ensure that you have registered the verified middleware in App\Http\Kernel.php:
protected $routeMiddleware = [
...
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,

Related

Laravel Fortify and JSON based registering result in CRSF mismatch

I'm currently toying with Laravel 9.x and Fortify.
For the starter here my environnement :
Laravel 9.19
Fortify 1.14
Postgre 15
I try to achieve something I thought was possible from reading the Fortify doc, using a third-party UI (e.g.: Mobile App) to register and login user.
So, following the documentation guide I deactivated the views generation, and migrated the tables and launched my test server using php artisan serve.
Then I try using postman to post the following json to the /register route provided by Fortify.
Postman has been setup with the following headers:
Content-Type: application/json
Accept: application/json
{
"name": "test1",
"email": "test1#example.com",
"password": "MyPassw0rd!",
"password_confirmation": "MyPassw0rd!"
}
The response returned by the request was an error 419 CSRF Token mismatch, which I understand since Laravel enforce the use of CSRF token.
Therefor I tried to add the /register route to the except array inside the middleware VerifyCsrfToken and tried again and this time I got a 201 created response.
From my understanding since the /register route exists within the web guard hence the CSRF token mechanic.
Since my final goal is to use Fortify with third-party frontend, how can achieve that without putting the route inside the except array (if possible)?
Is there a parameter to change inside config/fortify.php to allow this behavior?
Thanks for reading.
After playing I found the solution inside the middleware section of config/fortify.php
Replacing
middleware => ['web'],
with
middleware => ['api'],
Allow to user the register route without having to deactivate the CSRF on the route .

Laravel default auth for login generating unexpected error

I am using laravel's (6.2) default auth for user authentication. In my login form when I hit the default login route('login') provided by laravel it is showing me the wrong credential provided error though my credentials are correct. I used a seeder to generate my first user(default user for the site) and used the global bcrypt() (also tried Hash::make()) method to hash my password. I am using 'file' session driver which comes default too.
The most interesting part is that when I fire the php artisan migrate:fresh --seed command or php artisan migrate following by php artisan db:seed command, the auth works fine for the first time, That means when I try to log in immediately after firing those command the auth works fine till logout. But after that, when I do log out manually or session turns invalid, I can't login even though my credentials are correct. Any solution for that?
For seeder reference here what I applied to make the default user
\App\User::create([
'name' => "John Doe",
'email' => 'john#example.com',
'password' => Hash::make('password')
]);
Do you check as Hash::check(normal_password,hashed_password); in login function?

Laravel 5.7 Email Verification Routes

On Laravel 5.7 Email verification feature added. But on my project i do not use the default route names and added a prefix for my own purpose. Now when i added following code to add the verify routes, it shows an error.
Auth::routes(['verify' => true]);
Error message shows that the verification.verify route does not exists. Where can i update this route name in my project? Or is it the only way to use this feature is to follow the default Auth Route names?
Project Source Code Is available at https://github.com/nasirkhan/laravel-starter/tree/l57
Instead of using Auth::routes(['verify' => true]); just use Auth::routes(); and manually add these routes:
Route::get('email/verify', 'Auth\VerificationController#show')->name('verification.notice');
Route::get('email/verify/{id}', 'Auth\VerificationController#verify')->name('verification.verify');
Route::get('email/resend', 'Auth\VerificationController#resend')->name('verification.resend');
Then customise as you want :)
Anyone who gets here and is looking for tompec's version for the latest Laravel, use the below. Notice the addition of /{hash}.
$this->get('email/verify', 'Auth\VerificationController#show')->name('verification.notice');
$this->get('email/verify/{id}/{hash}', 'Auth\VerificationController#verify')->name('verification.verify');
$this->post('email/resend', 'Auth\VerificationController#resend')->name('verification.resend');
When you want to change the route throught which the verification process will be done you must change all the way the verification process work.
Email verification notification process
During the registration process an event Illuminate\Auth\Events\Registered is emit. Laravel come whith a listener Illuminate\Auth\Listeners\SendEmailVerificationNotification which is already registered in the App\Providers\EventServiceProvider.
After implementing the MustVerifyEmail interface when the Registered event is emit the SendEmailVerificationNotification listener will check if the App\User have already use the Illuminate\Contracts\Auth\MustVerifyEmail trait by checking if the user create is an instance of MustVerifyEmail if that is the case it will call the sendEmailVerificationNotification method on the user which get the implementation of this method when it use the Illuminate\Auth\MustVerify trait.
Customization of the verification route
To change the behavior of the verification process you can customize the sendEmailVerificationNotification to emit a custom event which can have a custom listener in which you will perform all the verification stuff and notify the user by email in which you will send the custom route through which the verification process will be done
In my case, I had the same issue and I was receiving the message
InvalidArgumentException
Attribute [auth] does not exist.
at vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php:92
I've solved it updating my composer executable file and laravel local files.
composer global self-update
composer update
It seems that my composer executable was using and old version of laravel installer.

Laravel Passport routes missing in route:list - 404 error on oauth/token

I have followed the Laravel 5.5 documentation to require, install and configure Laravel Passport on our application. We are ONLY using the password grant functionality as we aren't intending to use this as a social login tool. However, after following all the instructions, I am getting a 404 error when attempting to POST the form data into the application using Postman.
I have run php artisan route:list and there is no mention in there of oauth at all. I'd share the output but it's quite long as we have a large application.
I have ensured that Passport::routes() is in the AuthServiceProvider as shown below:
<?php
namespace App\Providers;
use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* #var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* #return void
*/
public function boot()
{
$this->registerPolicies();
Passport::routes();
//
}
}
The documentation on 5.5 does not say anything about adding a line to the config/app.php file as previous versions of Laravel do. After getting the 404 errors I decided to try adding that line just to see if it helps. It does not.
I did in fact run php artisan passport:install and then php artisan migrate which resulted in the creation of 2 clients: (ID = 1: Personal Access Client) and ID 2: Password Grant Client) and the various oauth tables being created in our database.
The resulting 404 error IS in fact coming from the site and not some generic message as it has our theme wrapped around it so I know it's hitting the application.
I have searched for references to the 404 error on oauth/token and Laravel Passport but have come up dry on solutions.
Any suggestions are greatly appreciated.
bingo bango I found the problem....
So after digging around, as mentioned in my comment above, the AuthServiceProvider in my App\Providers folder was not referenced. I had commented out the Illuminate one and added my App\Providers one thinking that it would simply extend the Illuminate one. That caused the Auth class error. I re-enabled the Illuminate one and left my App\Providers\AuthServiceProvider enabled but below the Illuminate one and it all worked out. No more 404s... Hope this helps someone else.
I had also the same problem and fixed with clearing the caches php artisan o:c
Check that you have the correct Passport version for Laravel:
composer require laravel/passport:~4.0
for Laravel 5.5 and 5.6

PHP laravel 4.2 API Routing URL with postman

I'm new to laravel4.2 trying to create a RESTFUL API, but getting error when I'm trying to hit URL{localhost/TPM/public/api/books} in postman.
what would be the URL for this??
Controller:
Router:
Try with return Response::json(['result' => true]); in your index method.
In addition, you can check the logs file for clues of what's going on in storage/logs/laravel.log.
I think in Laravel 4.2 you needed to perform a composer dump-autoload if created new classes but not sure.

Categories