Back
AppwriteException: Invalid relationship value. Must be either a document ID or a document, array giv
- 0
- Self Hosted
- Web
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.@Steven
Is there any work around
here
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",
};
}
}
@შონია
Recommended threads
- is `account.get()` safe to be used in th...
I want to user's `id` for authentication. However, a while ago I was told in this server not to use `account.get()` and instead add user preferences for that us...
- Usage of the new Client() and dealing wi...
Hey guys, just a quick one - we had some web traffic the other day and it ended up bombing out - To put in perspective of how the app works, we have a Nuxt Ap...
- [Beginner] CLI --queries Syntax Error & ...
Hi everyone! I am a beginner with Appwrite and trying to use the CLI, but I'm stuck with a syntax error. Any guidance would be greatly appreciated! 🙏 **Enviro...