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

[UX] Allow to redirect logged-in user on any routes and add a redirection for registration page #15418

Open
wants to merge 10 commits into
base: 1.14
Choose a base branch
from

Conversation

Jibbarth
Copy link
Contributor

@Jibbarth Jibbarth commented Oct 8, 2023

Q A
Branch? 1.14
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets fixes #9984
License MIT

When a logged-in user visit registration page, he is now redirected directly to account dashboard page, like for /login.

I targetted the sylius.customer.initialize_register dispatched by the resource controller to not use a Request event that will be triggered on every page.

However, while coding, as I added the logged_in_route in register route configuration, I was wondering if it wouldn't be better to add a generic event that check every route for the logged_in_route attribute, and in such case, we can perform the redirection.

I think it would be nice to have this ability to define a logged_in_route to redirect on every route. WDYT ?


EDIT

We can now add a logged_in_route in any route, and the redirection will occur as soon as we are logged_in.

Two way to add the attribute :

any_route:
    # ...
    defaults:
        _sylius:
            logged_in_route: sylius_shop_account_dashboard
any_route:
    # ...
    defaults:
        _sylius:
            logged_in_route: 
                name: sylius_shop_account_dashboard
                parameters: 
                    param1: value1

@Jibbarth Jibbarth requested a review from a team as a code owner October 8, 2023 16:10
@probot-autolabeler probot-autolabeler bot added the Shop ShopBundle related issues and PRs. label Oct 8, 2023
@Jibbarth Jibbarth changed the title [UX][Shop] Redirect to dashboard a logged-in user that reach register page [UX][Shop] Redirect to dashboard a logged-in user who reach register page Oct 8, 2023
@github-actions
Copy link

github-actions bot commented Oct 8, 2023

Bunnyshell Preview Environment deployment failed

Check https://github.com/Sylius/Sylius/actions/runs/7862012607 for details.

Available commands:

  • /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@Prometee
Copy link
Contributor

Prometee commented Oct 8, 2023

@Jibbarth I test a different approach here because I use a different security config than the one present in sylius/sylius-standard :

security:
    firewalls:
        shop:
            form_login:
                default_target_path: sylius_shop_account_dashboard

In the case I'm a registered customer and I register a second one I'm redirected to the dashboard.

One drawback I saw : if your channel is configured to required the account verification then after the registration you are not logged in as the new customer.

@Jibbarth
Copy link
Contributor Author

Jibbarth commented Oct 8, 2023

@Prometee 🤔 I'm not sure to follow you. The snippet you provide is for redirecting after login, right ?

Here, we'll make a redirection for an already logged-in user that try to reach /register page, coming from google or directly from url.

There is already such things for /login page here: https://github.com/Sylius/Sylius/blob/1.13/src/Sylius/Bundle/UiBundle/Controller/SecurityController.php#L39-L43

But maybe I missed something 😅

@Jibbarth
Copy link
Contributor Author

Jibbarth commented Oct 8, 2023

😱 oh no, my behat test seems no valid. Any clue to fix this?

@Prometee
Copy link
Contributor

Prometee commented Oct 8, 2023

@Jibbarth nevermind I though you wanted to allow redirecting to the dashboard when already logged in. I didn't understand that you wanted to avoid this behaviour, sorry for that.

Copy link
Member

@diimpp diimpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to have this ability to define a logged_in_route to redirect on every route. WDYT ?

Sounds nice, though I didn't work with html shop for years and don't have an opinion.

@Jibbarth Jibbarth force-pushed the feature/redirect-logged-in-user-when-visit-registration-page branch from 777684f to 74f1b64 Compare October 14, 2023 10:27
diimpp
diimpp previously approved these changes Oct 22, 2023
oallain
oallain previously approved these changes Nov 24, 2023
Copy link
Member

@oallain oallain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@Jibbarth
Copy link
Contributor Author

Jibbarth commented Feb 5, 2024

Sorry @Rafikooo, i didn't see your comments. I'll try to address them as soon as possible 😉

@Jibbarth Jibbarth dismissed stale reviews from oallain and diimpp via b6f21d7 February 11, 2024 12:38
@Jibbarth Jibbarth force-pushed the feature/redirect-logged-in-user-when-visit-registration-page branch from d446e17 to b6f21d7 Compare February 11, 2024 12:38
@Jibbarth Jibbarth requested a review from a team as a code owner February 11, 2024 12:38
@Jibbarth
Copy link
Contributor Author

Comments addressed @Rafikooo 😉

To handle both Login and registration behavior in the Listener, I moved it in UiBundle, cause the SecurityController act also for admin login.

Moreover, the event is now more flexible.

We can add a logged_in_route in any route, and the redirection will occur as soon as we are logged_in.

Two way to add the attribute :

any_route:
    # ...
    defaults:
        _sylius:
            logged_in_route: sylius_shop_account_dashboard
any_route:
    # ...
    defaults:
        _sylius:
            logged_in_route: 
                name: sylius_shop_account_dashboard
                parameters: 
                    param1: value1

// case logged_in_route:
// name: 'app_route'
// parameters:
// param1: 'value1'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tell me if such comment are not needed

@@ -40,6 +41,7 @@ public function __construct(
private LoginPageInterface $loginPage,
private NotificationCheckerInterface $notificationChecker,
private SharedStorageInterface $sharedStorage,
private RegisterPageInterface $registerPage,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell me if we should gather PageInterface together in order's declaration

@Jibbarth Jibbarth changed the title [UX][Shop] Redirect to dashboard a logged-in user who reach register page [UX] Allow to redirect logged-in user on any routes Feb 11, 2024
@Jibbarth Jibbarth changed the title [UX] Allow to redirect logged-in user on any routes [UX] Allow to redirect logged-in user on any routes and add a redirection for registration page Feb 11, 2024
@Jibbarth Jibbarth requested a review from Rafikooo March 11, 2024 12:31
@Rafikooo Rafikooo self-assigned this Mar 12, 2024
@Jibbarth Jibbarth changed the base branch from 1.13 to 1.14 June 11, 2024 14:58
@Jibbarth
Copy link
Contributor Author

Jibbarth commented Oct 8, 2024

Happy birthday little PR 🥳

@Rafikooo, is there anything else I can do here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Shop ShopBundle related issues and PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redirect logged in users to /account/dashboard when trying to access /register or /login
5 participants