Back
AppwriteException: Invalid relationship value. Must be either a document ID or a document, array giv
- 0
- Self Hosted
- Web
Misho
I am updating user, more correctly i am update user profile image of user and i get this error:
TypeScript
code: 400,
type: 'relationship_value_invalid',
response: {
message: 'Invalid relationship value. Must be either a document ID or a document, array given.',
code: 400,
type: 'relationship_value_invalid',
version: '1.5.7'
}
}
TL;DR
Developers are encountering an error when updating a user profile image due to an "Invalid relationship value" message. The issue lies in passing an array instead of a document ID. To resolve this, ensure the correct data type is provided as the relationship value when updating the user profile image. Misho
@Steven
Misho
Is there any work around
Misho
here
Misho
TypeScript
"use server";
import {
createSessionClient,
} from "@/lib/utils/appwrite-server";
import { envi } from "@/lib/utils/env";
import { User } from "../../types";
import { updateUserSchema } from "./update-user.schema";
import { Query } from "node-appwrite";
import { revalidatePath } from "next/cache";
export default async function updateUser(
id: User["$id"],
values: unknown
) {
try {
const res = updateUserSchema.parse(values);
const { databases, teams } = await createSessionClient();
try {
const membership = await teams.listMemberships(
envi.NEXT_PUBLIC_NEW_USERS_TEAM_ID,
[Query.equal("userId", id)]
);
if (membership.total > 0) {
const membershipId = membership.memberships[0].$id;
await teams.deleteMembership(
envi.NEXT_PUBLIC_NEW_USERS_TEAM_ID,
membershipId
);
}
} catch (error) {}
await databases.updateDocument(
envi.NEXT_PUBLIC_HOPPLA_DATABASE_ID,
envi.NEXT_PUBLIC_USERS_COLLECTION_ID,
id,
res
);
revalidatePath("/");
return {};
} catch (error) {
console.error(error)
return {
error: "An unexpected error occurred when updating user",
};
}
}
Misho
@შონია
Recommended threads
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...