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
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...
- Type Mismatch in AppwriteException
There is a discrepancy in the TypeScript type definitions for AppwriteException. The response property is defined as a string in the type definitions, but in pr...