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

Exception 'Route [aimeos_shop_account] not defined' when visiting shop page while logged in as admin #482

Closed
gitbuddy99 opened this issue Mar 10, 2023 · 11 comments

Comments

@gitbuddy99
Copy link

gitbuddy99 commented Mar 10, 2023

Environment

  1. Version 2020.10
  2. Operating system Linux, docker,sail, php 8.2.3, laravel 10.3.3

Describe the bug
Just installed. initially worked as expected (routes /shop and /admin).
Then I started getting "Route [aimeos_shop_account] not defined."
After some digging, I found that when I visit the shop page from the same browser I'm logged as admin, the Profile link airoute( 'aimeos_shop_account' ) throws an exception.
If I visit the same page in a logged-out/private/incognito browser, the shop pages load fine.
Also, on the shop page the Login link points to /login, which goes to the Laravel/Breeze login page, not the shop one.

To Reproduce
Steps to reproduce the behavior:

  1. Log in as admin
  2. Go to shop page

Expected behavior
open shop pages

Screenshots
Screenshot from 2023-03-10 12-27-02

Additional context

./artisan route:list

  GET|HEAD  / ....................................................................................................................................... aimeos_home › Aimeos\Shop › CatalogController@homeAction
  POST      _ignition/execute-solution ......................................................................................... ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController
  GET|HEAD  _ignition/health-check ..................................................................................................... ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
  POST      _ignition/update-config .................................................................................................. ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController
  GET|HEAD  admin .............................................................................................................................. aimeos_shop_admin › Aimeos\Shop › AdminController@indexAction
  POST      admin/{site}/graphql ...................................................................................................... aimeos_shop_graphql_post › Aimeos\Shop › GraphqlController@indexAction
  POST      admin/{site}/jqadm/batch/{resource} .......................................................................................... aimeos_shop_jqadm_batch › Aimeos\Shop › JqadmController@batchAction
  GET|HEAD  admin/{site}/jqadm/copy/{resource}/{id} ........................................................................................ aimeos_shop_jqadm_copy › Aimeos\Shop › JqadmController@copyAction
  GET|HEAD  admin/{site}/jqadm/create/{resource} ....................................................................................... aimeos_shop_jqadm_create › Aimeos\Shop › JqadmController@createAction
  POST      admin/{site}/jqadm/delete/{resource}/{id?} ................................................................................. aimeos_shop_jqadm_delete › Aimeos\Shop › JqadmController@deleteAction
  GET|POST|HEAD admin/{site}/jqadm/export/{resource} ................................................................................... aimeos_shop_jqadm_export › Aimeos\Shop › JqadmController@exportAction
  GET|HEAD  admin/{site}/jqadm/file/{type} ................................................................................................. aimeos_shop_jqadm_file › Aimeos\Shop › JqadmController@fileAction
  GET|HEAD  admin/{site}/jqadm/get/{resource}/{id} ........................................................................................... aimeos_shop_jqadm_get › Aimeos\Shop › JqadmController@getAction
  POST      admin/{site}/jqadm/save/{resource} ............................................................................................. aimeos_shop_jqadm_save › Aimeos\Shop › JqadmController@saveAction
  GET|POST|HEAD admin/{site}/jqadm/search/{resource} ................................................................................... aimeos_shop_jqadm_search › Aimeos\Shop › JqadmController@searchAction
  OPTIONS   admin/{site}/jsonadm/{resource?} ..................................................................................... aimeos_shop_jsonadm_options › Aimeos\Shop › JsonadmController@optionsAction
  DELETE    admin/{site}/jsonadm/{resource}/{id?} .................................................................................. aimeos_shop_jsonadm_delete › Aimeos\Shop › JsonadmController@deleteAction
  GET|HEAD  admin/{site}/jsonadm/{resource}/{id?} ........................................................................................ aimeos_shop_jsonadm_get › Aimeos\Shop › JsonadmController@getAction
  PATCH     admin/{site}/jsonadm/{resource}/{id?} .................................................................................... aimeos_shop_jsonadm_patch › Aimeos\Shop › JsonadmController@patchAction
  POST      admin/{site}/jsonadm/{resource}/{id?} ...................................................................................... aimeos_shop_jsonadm_post › Aimeos\Shop › JsonadmController@postAction
  PUT       admin/{site}/jsonadm/{resource}/{id?} ........................................................................................ aimeos_shop_jsonadm_put › Aimeos\Shop › JsonadmController@putAction
  GET|HEAD  api/user ......................................................................................................................................................................................... 
  GET|HEAD  confirm-password ...................................................................................................................... password.confirm › Auth\ConfirmablePasswordController@show
  POST      confirm-password ........................................................................................................................................ Auth\ConfirmablePasswordController@store
  GET|HEAD  dashboard .............................................................................................................................................................................. dashboard
  POST      email/verification-notification ........................................................................................... verification.send › Auth\EmailVerificationNotificationController@store
  GET|HEAD  forgot-password ....................................................................................................................... password.request › Auth\PasswordResetLinkController@create
  POST      forgot-password .......................................................................................................................... password.email › Auth\PasswordResetLinkController@store
  GET|OPTIONS|HEAD jsonapi/{resource?} ........................................................................................... aimeos_shop_jsonapi_options › Aimeos\Shop › JsonapiController@optionsAction
  DELETE    jsonapi/{resource} ..................................................................................................... aimeos_shop_jsonapi_delete › Aimeos\Shop › JsonapiController@deleteAction
  GET|HEAD  jsonapi/{resource} ........................................................................................................... aimeos_shop_jsonapi_get › Aimeos\Shop › JsonapiController@getAction
  PATCH     jsonapi/{resource} ....................................................................................................... aimeos_shop_jsonapi_patch › Aimeos\Shop › JsonapiController@patchAction
  POST      jsonapi/{resource} ......................................................................................................... aimeos_shop_jsonapi_post › Aimeos\Shop › JsonapiController@postAction
  PUT       jsonapi/{resource} ........................................................................................................... aimeos_shop_jsonapi_put › Aimeos\Shop › JsonapiController@putAction
  GET|HEAD  login ......................................................................................................................................... login › Auth\AuthenticatedSessionController@create
  POST      login .................................................................................................................................................. Auth\AuthenticatedSessionController@store
  POST      logout ...................................................................................................................................... logout › Auth\AuthenticatedSessionController@destroy
  GET|POST|HEAD p/{path?} ............................................................................................................................. aimeos_page › Aimeos\Shop › PageController@indexAction
  PUT       password ........................................................................................................................................ password.update › Auth\PasswordController@update
  GET|HEAD  profile .................................................................................................................................................... profile.edit › ProfileController@edit
  PATCH     profile ................................................................................................................................................ profile.update › ProfileController@update
  DELETE    profile .............................................................................................................................................. profile.destroy › ProfileController@destroy
  GET|POST|HEAD profile/download/{dl_id} ....................................................................................... aimeos_shop_account_download › Aimeos\Shop › AccountController@downloadAction
  GET|POST|HEAD profile/favorite/{fav_action?}/{fav_id?}/{d_name?}/{d_pos?} ....................................................... aimeos_shop_account_favorite › Aimeos\Shop › AccountController@indexAction
  GET|POST|HEAD profile/watch/{wat_action?}/{wat_id?}/{d_name?}/{d_pos?} ............................................................. aimeos_shop_account_watch › Aimeos\Shop › AccountController@indexAction
  GET|HEAD  register ......................................................................................................................................... register › Auth\RegisteredUserController@create
  POST      register ..................................................................................................................................................... Auth\RegisteredUserController@store
  POST      reset-password ................................................................................................................................. password.store › Auth\NewPasswordController@store
  GET|HEAD  reset-password/{token} ........................................................................................................................ password.reset › Auth\NewPasswordController@create
  GET|HEAD  sanctum/csrf-cookie ............................................................................................................ sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show
  GET|POST|HEAD shop ........................................................................................................................... aimeos_shop_list › Aimeos\Shop › CatalogController@listAction
  GET|POST|HEAD shop/basket .................................................................................................................. aimeos_shop_basket › Aimeos\Shop › BasketController@indexAction
  GET|POST|HEAD shop/checkout/{c_step?} .................................................................................................. aimeos_shop_checkout › Aimeos\Shop › CheckoutController@indexAction
  GET|POST|HEAD shop/confirm/{code?} .................................................................................................... aimeos_shop_confirm › Aimeos\Shop › CheckoutController@confirmAction
  GET|POST|HEAD shop/count ................................................................................................................... aimeos_shop_count › Aimeos\Shop › CatalogController@countAction
  GET|POST|HEAD shop/pin .......................................................................................................... aimeos_shop_session_pinned › Aimeos\Shop › CatalogController@sessionAction
  GET|POST|HEAD shop/stock ................................................................................................................... aimeos_shop_stock › Aimeos\Shop › CatalogController@stockAction
  GET|POST|HEAD shop/suggest ............................................................................................................. aimeos_shop_suggest › Aimeos\Shop › CatalogController@suggestAction
  GET|POST|HEAD shop/{d_name}/{d_pos?}/{d_prodid?} ......................................................................................... aimeos_shop_detail › Aimeos\Shop › CatalogController@detailAction
  GET|POST|HEAD shop/{f_name}~{f_catid}/{l_page?} .............................................................................................. aimeos_shop_tree › Aimeos\Shop › CatalogController@treeAction
  GET|POST|HEAD supplier/{s_name}/{f_supid} ............................................................................................. aimeos_shop_supplier › Aimeos\Shop › SupplierController@detailAction
  GET|POST|HEAD update .................................................................................................................... aimeos_shop_update › Aimeos\Shop › CheckoutController@updateAction
  GET|HEAD  verify-email ........................................................................................................................ verification.notice › Auth\EmailVerificationPromptController
  GET|HEAD  verify-email/{id}/{hash} ........................................................................................................................ verification.verify › Auth\VerifyEmailController

                                                                                                                                                                                           Showing [64] routes
@gitbuddy99 gitbuddy99 changed the title Route [aimeos_shop_account] not defined. Exception 'Route [aimeos_shop_account] not defined' when visiting shop page while logged in as admin Mar 11, 2023
@aimeos
Copy link
Owner

aimeos commented Mar 11, 2023

Aimeos aimeos_shop_profile route for /profile seems to be overwritten by a ProfileController. Is this your own implementation?

Login is handled by Laravel Breeze, also for the shop. If you want to style it differently, you need to adapt the Laravel auth templates.

@gitbuddy99
Copy link
Author

I haven't implemented anything. It's just a new install following the instructions from https://github.com/aimeos/aimeos-laravel step by step.
Thanks for any assistance you can provide.

@aimeos
Copy link
Owner

aimeos commented Mar 11, 2023

Unfortunately, Laravel Breeze adds a controller in app/Http/Controllers/ProfileController.php and a route for /profile in ./routes/web.php which may overwrite the aimeos_shop_account route. To remove the Laravel Breeze routes, remove these lines from ./routes/web.php file:

Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

@gitbuddy99
Copy link
Author

That allows an admin to access the shop page, but kills the path for a regular user to open an account. Can't use the /register Breeze endpoint when removing these routes.
Does aimeos include an alternate path a customer can use to open an account?

@aimeos
Copy link
Owner

aimeos commented Mar 11, 2023

Yes, new customers will be registered by default when they have finished the checkout (and they didn't opt out).

@aimeos
Copy link
Owner

aimeos commented Mar 11, 2023

Breeze redirects to RouteServiceProvider::HOME here: https://github.com/laravel/breeze/blob/1.x/stubs/default/app/Http/Controllers/Auth/RegisteredUserController.php#L49

Maybe it's enough to change that value.

@gitbuddy99
Copy link
Author

Sorry, I don't understand. You mean modify the breeze controller? What should that value be changed to?

@aimeos
Copy link
Owner

aimeos commented Mar 12, 2023

Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

Can you try to change these routes to /profile/me?

@MahmoudDevo
Copy link

MahmoudDevo commented Mar 16, 2023

Hi,
Yes Laravel Breeze change the web.php configuration after creation ProfileController and that's prevent access to /admin:
for example:
http://127.0.0.1:8000/admin/default/jqadm/search/dashboard?locale=en
diplay: 403 THIS ACTION IS UNAUTHORIZED.

using aimeos Headless, Laravel Breeze and Inertia STOP acces to admin page.

remove from web.php the code below:
Route::get('/', function () { return redirect(route('aimeos_shop_jsonapi_options')); });

I changed to '/profile/me' but the issue remains unchanged.

@aimeos
Copy link
Owner

aimeos commented Mar 21, 2023

@MahmoudDevo: Creating a new project from aimeos/aimeos-headless including Laravel Breeze works without problems in our tests for 2022.10.x and dev-master.

2022.10.x:
Uses Laravel 9.x and Breeze 1.19 which doesn't have the /profile routes so there's no problem at all.

dev-master:
Uses Laravel 10.x and Breeze 1.20 which adds /profile route but that isn't used by Aimeos in the headless distribution.

Here are the registered routes for Aimeos dev-master:

 GET|HEAD  admin ......................................................................................... aimeos_shop_admin › Aimeos\Shop › AdminController@indexAction
  POST      admin/{site}/graphql ................................................................. aimeos_shop_graphql_post › Aimeos\Shop › GraphqlController@indexAction
  POST      admin/{site}/jqadm/batch/{resource} ..................................................... aimeos_shop_jqadm_batch › Aimeos\Shop › JqadmController@batchAction
  GET|HEAD  admin/{site}/jqadm/copy/{resource}/{id} ................................................... aimeos_shop_jqadm_copy › Aimeos\Shop › JqadmController@copyAction
  GET|HEAD  admin/{site}/jqadm/create/{resource} .................................................. aimeos_shop_jqadm_create › Aimeos\Shop › JqadmController@createAction
  POST      admin/{site}/jqadm/delete/{resource}/{id?} ............................................ aimeos_shop_jqadm_delete › Aimeos\Shop › JqadmController@deleteAction
  GET|POST|HEAD admin/{site}/jqadm/export/{resource} .............................................. aimeos_shop_jqadm_export › Aimeos\Shop › JqadmController@exportAction
  GET|HEAD  admin/{site}/jqadm/file/{type} ............................................................ aimeos_shop_jqadm_file › Aimeos\Shop › JqadmController@fileAction
  GET|HEAD  admin/{site}/jqadm/get/{resource}/{id} ...................................................... aimeos_shop_jqadm_get › Aimeos\Shop › JqadmController@getAction
  POST      admin/{site}/jqadm/save/{resource} ........................................................ aimeos_shop_jqadm_save › Aimeos\Shop › JqadmController@saveAction
  GET|POST|HEAD admin/{site}/jqadm/search/{resource} .............................................. aimeos_shop_jqadm_search › Aimeos\Shop › JqadmController@searchAction
  OPTIONS   admin/{site}/jsonadm/{resource?} ................................................ aimeos_shop_jsonadm_options › Aimeos\Shop › JsonadmController@optionsAction
  DELETE    admin/{site}/jsonadm/{resource}/{id?} ............................................. aimeos_shop_jsonadm_delete › Aimeos\Shop › JsonadmController@deleteAction
  GET|HEAD  admin/{site}/jsonadm/{resource}/{id?} ................................................... aimeos_shop_jsonadm_get › Aimeos\Shop › JsonadmController@getAction
  PATCH     admin/{site}/jsonadm/{resource}/{id?} ............................................... aimeos_shop_jsonadm_patch › Aimeos\Shop › JsonadmController@patchAction
  POST      admin/{site}/jsonadm/{resource}/{id?} ................................................. aimeos_shop_jsonadm_post › Aimeos\Shop › JsonadmController@postAction
  PUT       admin/{site}/jsonadm/{resource}/{id?} ................................................... aimeos_shop_jsonadm_put › Aimeos\Shop › JsonadmController@putAction
  POST      api/login .............................................................................................................................. AuthController@login
  POST      api/logout ............................................................................................................................ AuthController@logout
  POST      api/me .................................................................................................................................... AuthController@me
  POST      api/refresh .......................................................................................................................... AuthController@refresh
  GET|HEAD  confirm-password ................................................................................. password.confirm › Auth\ConfirmablePasswordController@show
  POST      confirm-password ................................................................................................... Auth\ConfirmablePasswordController@store
  GET|HEAD  dashboard ......................................................................................................................................... dashboard
  POST      email/verification-notification ...................................................... verification.send › Auth\EmailVerificationNotificationController@store
  GET|HEAD  forgot-password .................................................................................. password.request › Auth\PasswordResetLinkController@create
  POST      forgot-password ..................................................................................... password.email › Auth\PasswordResetLinkController@store
  GET|OPTIONS|HEAD jsonapi/{resource?} ...................................................... aimeos_shop_jsonapi_options › Aimeos\Shop › JsonapiController@optionsAction
  DELETE    jsonapi/{resource} ................................................................ aimeos_shop_jsonapi_delete › Aimeos\Shop › JsonapiController@deleteAction
  GET|HEAD  jsonapi/{resource} ...................................................................... aimeos_shop_jsonapi_get › Aimeos\Shop › JsonapiController@getAction
  PATCH     jsonapi/{resource} .................................................................. aimeos_shop_jsonapi_patch › Aimeos\Shop › JsonapiController@patchAction
  POST      jsonapi/{resource} .................................................................... aimeos_shop_jsonapi_post › Aimeos\Shop › JsonapiController@postAction
  PUT       jsonapi/{resource} ...................................................................... aimeos_shop_jsonapi_put › Aimeos\Shop › JsonapiController@putAction
  GET|HEAD  login .................................................................................................... login › Auth\AuthenticatedSessionController@create
  POST      login ............................................................................................................. Auth\AuthenticatedSessionController@store
  POST      logout ................................................................................................. logout › Auth\AuthenticatedSessionController@destroy
  PUT       password ................................................................................................... password.update › Auth\PasswordController@update
  GET|HEAD  profile ............................................................................................................... profile.edit › ProfileController@edit
  PATCH     profile ........................................................................................................... profile.update › ProfileController@update
  DELETE    profile ......................................................................................................... profile.destroy › ProfileController@destroy
  GET|HEAD  register .................................................................................................... register › Auth\RegisteredUserController@create
  POST      register ................................................................................................................ Auth\RegisteredUserController@store
  POST      reset-password ............................................................................................ password.store › Auth\NewPasswordController@store
  GET|HEAD  reset-password/{token} ................................................................................... password.reset › Auth\NewPasswordController@create
  GET|HEAD  sanctum/csrf-cookie ....................................................................... sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show
  GET|POST|HEAD update ............................................................................... aimeos_shop_update › Aimeos\Shop › CheckoutController@updateAction
  GET|HEAD  verify-email ................................................................................... verification.notice › Auth\EmailVerificationPromptController
  GET|HEAD  verify-email/{id}/{hash} ................................................................................... verification.verify › Auth\VerifyEmailController

403 THIS ACTION IS UNAUTHORIZED sounds like an authentication or session problem which must be caused by something else then the additonal /profile route.

@aimeos
Copy link
Owner

aimeos commented Mar 21, 2023

@gitbuddy99 For Laravel 10.x, Breeze 1.20+ and Aimeos Laravel extension 2022.10.x, changing the Breeze routes in ./routes/web.php from:

Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

to

Route::middleware('auth')->group(function () {
    Route::get('/profile/me', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile/me', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile/me', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

solved the problem.

@aimeos aimeos closed this as completed Aug 20, 2023
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

3 participants