Skip to content

Create User Document option overwrites existing user document #1207

@Shubham-VE

Description

@Shubham-VE

Has your issue been reported?

  • I have searched the existing issues and confirm it has not been reported.
  • I give permission for members of the FlutterFlow team to access and test my project for the sole purpose of investigating this issue.

Current Behavior

The app has login via JWT with the "Create User Document" option enabled. Recently, when a user tries to log in sometimes randomly his user document is overwritten, even though the user document exists already, by the fields mentioned in the "Create User Document" description. This happens especially when you clear the cache and try to log in again. This issue only occurs on the Web. I have confirmed this issue by changing the code as below:

// Creates a Firestore document representing the logged in user if it doesn't yet exist
Future maybeCreateUser(User user) async {
  final userRecord = UsersRecord.collection.doc(user.uid);
  final userExists = await userRecord.get().then((u) => u.exists);
  if (userExists) {
    currentUserDocument = await UsersRecord.getDocumentOnce(userRecord);
    return;
  }

  final userData = createUsersRecordData(
    email: user.email,
    displayName: user.displayName,
    photoUrl: user.photoURL,
    uid: user.uid,
    phoneNumber: user.phoneNumber,
    createdTime: getCurrentTimestamp,
  );
  print('Login User being set $userData'); //added this
  await userRecord.set(userData, SetOptions(merge: true)); // set merge to true to prevent overwrite
  currentUserDocument = UsersRecord.getDocumentFromData(userData, userRecord);
}

On the console the message has been printed there meaning the document ahs been overwritten even though the user document already exists.
Screenshot 2023-08-03 at 11 05 58 AM
The user document created_time has been also updated, if not for the above updated code it would have been wiped out except for a few fields.
Screenshot 2023-08-03 at 11 07 02 AM

Expected Behavior

Login normally without any side effects.

Steps to Reproduce

  1. Create a basic login page
  2. Login via JWT with the "Create User Document" option enabled.
  3. For an existing user, login - logout and login, clear cache, and log in again multiple times as this issue is random. Test this on web.
  4. Check if the user document has been overwritten.

Reproducible from Blank

  • The steps to reproduce above start from a blank project.

Bug Report Code (Required)

IT48l/HLuMlOxLhc+KqNdcdKqCYWHHk7aIJIjdZTY008KOPdOoYUP8+kM0RBTbC8d2w7IUyZkWoW0MLFv+PLFPEDGzeVRZxbws92dArKc3Ojbr3RFJWgPHFADe5nBWaZyKTUsyZdKtBYSnw63Tuyf96QaBPUHr7RNlcGD6/LZO4=

Context

Trying to log in normally but instead end up losing user data.

Visual documentation

Enable this option
Screenshot 2023-08-03 at 12 21 26 PM

Additional Info

No response

Environment

- FlutterFlow version:v3.1 (released July 27, 2023)
- Platform: Web
- Browser name and version: Chrome 115.0.5790.114 (Official Build) (arm64)
- Operating system and version affected:

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions