export const getByIdInfo = query({
args: {
diagramId: v.optional(v.id("diagrams")),
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (!args.diagramId) {
return; // No diagramId provided
}
const document = await ctx.db.get(args.diagramId);
if (!document) {
throw new Error("Document not found or unauthorized access");
}
if (!identity || document.userId !== identity.subject) {
throw new Error("Unauthorized access");
}
return { ...document }; // Return the document information
},
});
export const getByIdInfo = query({
args: {
diagramId: v.optional(v.id("diagrams")),
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (!args.diagramId) {
return; // No diagramId provided
}
const document = await ctx.db.get(args.diagramId);
if (!document) {
throw new Error("Document not found or unauthorized access");
}
if (!identity || document.userId !== identity.subject) {
throw new Error("Unauthorized access");
}
return { ...document }; // Return the document information
},
});