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
- Which flutter SDK version for Self Hoste...
Hi all, Is there a good way to figure out which version of flutter SDK and Dart SDK is current for latest available self-hosted 1.8.0 ? I know new features are...
- Bug Report: Crash when trying to createR...
https://github.com/appwrite/sdk-for-android/issues/96 I think the bug is related with this one https://discord.com/channels/564160730845151244/1443887021314539...
- redirect_uri errors on flutter client
Hi all, I'm using the flutter client for my app to do appwrite auth and use the JWTs to send to my backend. When I try to sign in with SSO, I get this: https:/...