dalenguyen / firebase-wordpress-plugin

A plugin that helps to integrate Firebase to WordPress
https://firebase-wordpress-docs.readthedocs.io
GNU General Public License v2.0
110 stars 31 forks source link

Redirect to referrer URL after successful Login / Registration #205

Closed ghayoor-cbq closed 1 year ago

ghayoor-cbq commented 1 year ago

When attempting to access a protected page such as https://example.com/membership, you are redirected to the login page as expected. However, after successfully logging in, you are taken to https://example.com/, which is not the desired outcome. The issue seems to originate from the [firebase_login redirect="/" skip_default_email="true"] configuration. When the redirect="/" parameter is removed, the system does not redirect you anywhere upon successful login, which is also not the intended behavior.

dalenguyen commented 1 year ago

Hi @ghayoor-cbq, thanks for the info? What is your desire behaviour? Can you replace the redirect="/" with redirect="/your-own-path"?

ghayoor-cbq commented 1 year ago

@dalenguyen The current implementation of redirect="/your-own-path" only allows redirection to a single predefined path. However, my desired behavior is to have dynamic redirection based on the originally requested route.

For instance, if a user tries to access https://example.com/membership without being logged in, they should be redirected to the login page. Upon successful login, they should be taken back to https://example.com/membership, rather than a static path specified by redirect="/your-own-path".

Similarly, if a user attempts to access https://example.com/subscriptions without being logged in, they should be taken to the login page. After successful authentication, the user should be redirected to https://example.com/subscriptions, as that was the initial route they were trying to access.

In summary, the desired functionality is to have the login process redirect users back to the specific route they were trying to access before being prompted to log in.

nicolaosm commented 1 year ago

Basically ... The change thats required in Integrate Firebase Pro plugin is this:

In the includes>public>class.firebase.php

This snippet that's responsible for redirection from wp-login.php to custom login page should change from this:

    if ('wp-login.php' == $pagenow && !is_user_logged_in()) {
      // Redirect to default login page or to dedicated page for login
      if (self::$options_auth['login_url']) {
        $redirect_url = self::$options_auth['login_url'];
        wp_redirect($redirect_url);
        exit();
      }
    }

Should changes to this:

    if ('wp-login.php' == $pagenow && !is_user_logged_in()) {
      // Get the current URL parameters
      $params = $_SERVER['QUERY_STRING'];
      // Redirect to default login page or to dedicated page for login with parameters
      if (self::$options_auth['login_url']) {
        $redirect_url = self::$options_auth['login_url'];
        // Append the parameters to the redirect URL
        if ($params) {
          $redirect_url .= '?' . $params;
        }
        wp_redirect($redirect_url);
        exit();
      }
    }

This way whatever was the parameter on wp-login.php will now move on to the new custom login page, so we can inject it in the data-redirect of the form.

Can we please request this change an update @dalenguyen ?

dalenguyen commented 1 year ago

Absolutely. I will add and release new version this weekend.

Thanks, @ghayoor-cbq @nicolaosm

nicolaosm commented 1 year ago

Thank you @dalenguyen

dalenguyen commented 1 year ago

Updated. Please download the latest version v3.27.0.

nicolaosm commented 1 year ago

Thanks @dalenguyen ! For some reason it doesn't update to 3.27.0 from wordpress: https://cln.sh/xbHMn8dJ

And when i download the zip file directy from techcater, the plugin still shows 3.26.0.

dalenguyen commented 1 year ago

Hi @nicolaosm, can you retry it? 🙏

nicolaosm commented 1 year ago

Yep! Works great. Thank you @dalenguyen

dalenguyen commented 1 year ago

Awesome. Please me know if you need help with anything.

On Sun, Apr 9, 2023 at 6:33 PM nicolaosm @.***> wrote:

Yep! Works great. Thank you @dalenguyen https://github.com/dalenguyen

— Reply to this email directly, view it on GitHub https://github.com/dalenguyen/firebase-wordpress-plugin/issues/205#issuecomment-1501107396, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADLWKPCKTZO7ADBYYLOJRHLXAKM77ANCNFSM6AAAAAAWRB66WI . You are receiving this because you were mentioned.Message ID: @.***>

--