I am working on migrating our application into Nova and not sure how to migrate our login system over.
The general purpose of the application is to pull client data out of our CMS and provide them with a dashboard for metrics. The login process will look at the User model/table and if not there it will attempt to authenticate via API into the CMS, then save the data to local table for the next login attempt.
Previously this was added to the App\Http\Controllers\Auth\LoginController and worked well. Will Nova the LoginController is burried in the Nova folder so do not want to edit that.
I think I can override the Authenticate middleware in the config\nova.php but not sure if that's the right way to go.
I have also looked at Guards but again that seems like a plan if I had different tables for different users. I want to use the User model just edit the authentication process to check the API if nothing in the local DB.
You can copy the file: "nova/resources/views/auth/login.blade.php" to your own apps resources folder. Put it in the exact same folder structure as in the /nova folder. Then edit that file in your resources folder and change the login route on the login form's method action to the route you want to use.
The moment you run php artisan make:auth in your nova powered fresh app, nova will default to the auth solution provided via controllers in app/Http/Controllers/Auth, this means you pretty much can implement the same business logic.
The only thing that requires some thought is the login screen as it's going to default to the generated one, but it's pretty easy to overwrite based on the nova login screen... only a coupe of routes need to be changed to reflect the routes generated by Laravel.
Thanks for the responses, much appreciated.
The issue is not the login page so much but modifying the authentication middleware/guard.
This it self would not be such a struggle if I wasn't using Laravel Nova as it's LoginController is buried away.
I am still working through documentation on guards, middleware etc, trying to determine the best way to make this happen.
The requirements have extended a little so now I need to authenticate 2 different types of user via an external API and then site admin via the local DB.
Again this not to hard for me to manager with Laravel but after adding Nova things are not the same as they ever was.
Hi I know this post is a few weeks old, but I came here with a similar question and this is how I solved my problems.
Look at the routes where you would like to overload the controllers from using artisan.
$php artisan route:list
Add a new route for this route with the same name to your own routes/web.php pointing to your own custom implementation of that controller in your project.
In my case.
Route::post('nova/login', 'Nova\LoginController@login')->name('nova.login');
add a loginController at: app/Http/Controllers/Nova/LoginController.php
I know this is old, but I just found a solution that works better for me.
In the Nova Service Provider, you can alias Nova's Login Controller for your own, meaning when the routing layer creates the Login Controller, it's using yours instead of Nova's.
Example:
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
$this->app->alias(
\App\Http\Controllers\Nova\LoginController::class,
\Laravel\Nova\Http\Controllers\LoginController::class
);
}
Liking how @mdeclaire disabled the original routes in the NovaServiceProvider->routes. But I prefer not to edit vendor files. Went with a redirect of the /nova/logout route in my web.php routes file instead:
Route::get('nova/logout', function () {
return redirect('/logout');
})->name('nova.logout');