joedixon / laravel-translation

Translation management for your Laravel application.
MIT License
698 stars 231 forks source link

Using Auth middleware cause redirect to login everytime #248

Closed malozaibi closed 1 year ago

malozaibi commented 2 years ago

Describe the bug Using the Auth middleware make the /languages link to redirect to login and never return to the page. (it keeps returning to login after each successful login)

To Reproduce Steps to reproduce the behavior:

  1. Go to config/translation.php
  2. change the middleware from web to auth 'route_group_config' => [ 'middleware' => 'auth', ],
  3. go to /languages
  4. it will redirect to login
  5. login and it will show login again and again

Expected behavior It should open the /languages after login or if previously logged in show it immediately

versions

Please fix it, Thank you

joedixon commented 1 year ago

To confirm, are you able to access the /languages route manually after logging in?

malozaibi commented 1 year ago

To confirm, are you able to access the /languages route manually after logging in?

Yes it redirect to the home

Note: I am using laravel/ui bootstrap auth

I was able to solve this issue manually by cuting the routes form your route file and past them in my own route with middleware auth

dansleboby commented 1 year ago

Full step top reproduces

composer create-project laravel/laravel .
compsoer require laravel/ui
php artisan ui bootstrap --auth
npm install
npm run build
@ set the DB in .env
php artisan migrate
composer require joedixon/laravel-translation
php artisan vendor:publish --provider="JoeDixon\Translation\TranslationServiceProvider"
@ edit translations.php and add auth middleware
dansleboby commented 1 year ago

I found the issue, because the route is outsite the web.php in this case a external package, the auth middleware need to be run with web

Thanks to https://stackoverflow.com/questions/35160144/authuser-returns-null

So if you set it like this it work fine

'route_group_config' => [
    'middleware' => ['web', 'auth'],
],

I hope it will help!

malozaibi commented 1 year ago

Thank you very much @dansleboby this solution worked for me.