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

Empty userId on synced Woocommerce memberships #185

Closed ciriousjoker closed 2 years ago

ciriousjoker commented 2 years ago

Describe the bug

To Reproduce Steps to reproduce the behavior:

I can't really provide reliable steps to reproduce this, maybe this works:

Expected behavior

The userId field in Firestore should never be empty if there exists a Firebase Auth user

Screenshots

image

Screenshots If applicable, add screenshots to help explain your problem. You can find the error code from inspecting the browser.

Desktop (please complete the following information):

Additional context

ciriousjoker commented 2 years ago

A couple of things I noticed:

Also, for context about the collection names: image

ciriousjoker commented 2 years ago

@dalenguyen

Reproduction steps:

  1. Create Wordpress account manually
  2. Update the user to trigger a sync to wp_users (fails, because no userId)
  3. Import the user into Firebase auth through your import plugin
  4. Update the user to trigger a sync to wp_users (fails, because no userId) <-- This shouldn't happen, after the import the userId field for that wordpress account should be set
  5. Log into the wordpress account via FirebaseUI
  6. Update the user to trigger a sync to wp_users (this works)

Possible solution:

ciriousjoker commented 2 years ago

@dalenguyen I managed to fix it.

Add this snippet into <plugin>/includes/service/class.firebase-service.php:

public function import_users_to_firebase($users) {
    ...

    // Set firebase_uid during import
    foreach($users as $user) {
        update_usermeta($user->ID, "firebase_uid", $user->user_login);
    }
    return ...;
}

I obviously cannot commit this anywhere, but feel free to include it in the next plugin version.

dalenguyen commented 2 years ago

Thanks, @CiriousJoker. It probably what happens. I will add it to the next release 🙌

dalenguyen commented 2 years ago

Updated to the plugin 🙏