1

Hi I have installed the Laravel 5.7 version and when I go to authenticated url it redirects to the login page, but after login it redirects to home page.

This authenticated url could be any url that is authenticated with laravel auth middleware.

Here is my example router resource code for the url:

Route::namespace('User')->group(function () {
    Route::middleware('auth')->resource('delivery', 'DeliveryController');
});

The default behavior is when we try to go to a authenticated url it should redirect to login and after login it should redirect back to the authenticated url.

Ex:

delivery->login->delivery

customer->login->customer

But the problem is whatever url I call it redirects to home page (which is the $redirectTo in LoginController) after login. I have installed the passport for API authentication. Can anyone suggest me where should I start looking?

Janaka Dombawela
  • 1,337
  • 4
  • 26
  • 49

1 Answers1

1

In your default Login Controller, which resides in app -> Http -> Controllers -> Auth, there is a protected property called $redirectTo, make it to wherever you want user to get redirected after login. By default is the homepage.

In your case, you should change it to /delivery

If you are using passport means your Laravel installation is working as API, in that case the redirection is a work of whatever front end you are using.

With help of Passport, you can authenticate user, generate access token and send it back to the front end as JSON or any other format based upon your app.

And then based upon that response, you manage redirects from your front end.

The $redirectTo property will help only if you use the default authorization mechanism of Laravel.

So I believe you are confusing Laravel authorization with Passport Authentication process which are two very different things.

Please make a further edit to your question and provide details of your app and what you are trying to achieve and why are you using Passport in order for anyone here to help you in the right direction.

Makes sense?

Abhay Maurya
  • 11,819
  • 8
  • 46
  • 64
  • Edited the answer – Abhay Maurya Feb 22 '19 at 08:04
  • In your default Login Controller, which resides in app -> Http -> Controllers -> Auth, there is a protected property called $redirectTo, make it to wherever you want user to get redirected after login. By default is the homepage. - This property is applied if you directly go into login page, if you are coming from auth middleware the default redirection should be the previous authenticated url. – Janaka Dombawela Feb 22 '19 at 08:43
  • If you are using passport means your Laravel installation is working as API, in that case the redirection is a work of whatever front end you are using. - I just want to know whether passport conflicts default authentication. – Janaka Dombawela Feb 22 '19 at 08:45
  • In your case, you should change it to /delivery - I have lot of urls like that, not delivery and again, the default behavior should be redirecting it to the appropriate page. – Janaka Dombawela Feb 22 '19 at 08:46