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

Redirecting to Nova resource from Laravel login #2098

Closed
whiteDigitalAI opened this issue Oct 31, 2019 · 6 comments
Closed

Redirecting to Nova resource from Laravel login #2098

whiteDigitalAI opened this issue Oct 31, 2019 · 6 comments

Comments

@whiteDigitalAI
Copy link

Hello Guys,

Our requirement is to login to 4 different tables and redirect users to Nova dashboards according to the roles. The login controllers are in Laravel as Nova supports only single Auth(Table). We are trying this for the past two days, played around with middleware,routes, redirects etc. but no luck. Any guidance is appreciated. Thanks in advance

@Zen0x7
Copy link

Zen0x7 commented Oct 31, 2019

Hi @whiteDigitalAI

To solve the users redirect you should:

  1. Add your own LoginController extending the base Nova LoginController overwritting the authenticated method:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class LoginController extends \Laravel\Nova\Http\Controllers\LoginController {
    /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        // You're authenticated!
        return redirect('/');
    }
}

And bind this extension on NovaServiceProvider:

<?php

namespace App\Providers;

use Laravel\Nova\Http\Controllers\LoginController;

...

class NovaServiceProvider extends NovaApplicationServiceProvider {

    ...

    public function register()
    {
        $this->app->bind(LoginController::class, \App\Http\Controllers\LoginController::class);
    }
}

And to solve multiple authentication tables is other issue. The before code solve the redirecting.

@whiteDigitalAI
Copy link
Author

Many Thanks for the quick guidance Demency.. Will try this and revert back..

Take care

@davidhemphill
Copy link
Contributor

Alternatively, just build the login flow as your project requires. We realize Nova's conventions may not work for everyone and expect there to be some customization from time to time.

@iBet7o
Copy link

iBet7o commented Jun 7, 2020

I fixed it like this, in a component add the following and it works.

  router.beforeEach((to, from, next) => {
      if (to.name == 'dashboard.custom') {
          next({
              name: 'index',
              params: {
                  resourceName: 'orders'
              }
          })
      } else {
          next()
      }
  })

@whiteDigitalAI
Copy link
Author

Thank you iBet7o

Best
Guna

@mrimran
Copy link

mrimran commented May 17, 2023

The clean solution for Nova 4 is here, I've not tested that on Nova 3 or below.

Inside NovaServiceProvider update the below method

public function register()
{
    \Laravel\Nova\Nova::$initialPath = '/resources/users'; //update it to any valid nova path
}

Happy coding :)

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

No branches or pull requests

5 participants