
Hey, trying to create an AppUser
document and it's giving me an error saying $id is not allowed for creating new documents, try update instead
, do I have to create the document then update it with the wanted $id? I just want the AppUser to have the same ID as the auth user ID

Set it as the document ID when creating

Can you share the createDocument
code

Yeah, I think it's because you have id in your user object. It should be passed in the documentId argument of the createDocument method instead

Future<AppUser> getUserData(String uid) async {
try {
final appUserDocument = await db.getDocument(
databaseId: AppwriteConstants.databaseId,
collectionId: AppwriteConstants.usersCollection,
documentId: uid,
);
return AppUser.fromMap(appUserDocument.toMap());
} on AppwriteException {
final AppUser appUser = AppUser(
$id: user!.$id,
email: user!.email,
name: user?.name,
);
final appUserDocument = await db.createDocument(
databaseId: AppwriteConstants.databaseId,
collectionId: AppwriteConstants.usersCollection,
documentId: appUser.$id!,
data: appUser.toMap(),
);
return AppUser.fromMap(appUserDocument.toMap());
}
}
sorry should've shared it right away

Change it to this
Future<AppUser> getUserData(String uid) async {
try {
final appUserDocument = await db.getDocument(
databaseId: AppwriteConstants.databaseId,
collectionId: AppwriteConstants.usersCollection,
documentId: uid,
);
return AppUser.fromMap(appUserDocument.toMap());
} on AppwriteException {
final AppUser appUser = AppUser(
email: user!.email,
name: user?.name,
);
final appUserDocument = await db.createDocument(
databaseId: AppwriteConstants.databaseId,
collectionId: AppwriteConstants.usersCollection,
documentId: user.$id!,
data: appUser.toMap(),
);
return AppUser.fromMap(appUserDocument.toMap());
}
}

This way you would set the documentId
as the user ID
And, it will be at appUserDocument.$id

OH

I get it

$id was in the AppUser, thank you!!

[SOLVED] Unable to create document with $id?
Recommended threads
- Two steps signIn with one user:
'm using appwrite to try two phase login, step 1: await account.createAnonymousSession(); or final appwriteUser = await account.create( ...
- Registering new flutter app
Hi, ive got an already build flutter app which works in development with appwrite. but with the built version i get an error that the client is not registered. ...
- Appwrite messaging api error
```=== Push Notification Function Started === Endpoint: https://fra.cloud.appwrite.io/v1 Project: 6899062700398ffeae4f Database: threed-dating-db Notification f...
