Fetching another document's data via id in query
schema.tsschema.tsimport { authTables } from "@convex-dev/auth/server";
import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
export default defineSchema({
...authTables,
announcements: defineTable({
text: v.string(),
userId: v.string(),
}),
events: defineTable({
title: v.string(),
description: v.string(),
date: v.string(),
imageId: v.string(),
userId: v.string(),
}),
messages: defineTable({
text: v.string(),
userId: v.string(),
}),
});import { authTables } from "@convex-dev/auth/server";
import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
export default defineSchema({
...authTables,
announcements: defineTable({
text: v.string(),
userId: v.string(),
}),
events: defineTable({
title: v.string(),
description: v.string(),
date: v.string(),
imageId: v.string(),
userId: v.string(),
}),
messages: defineTable({
text: v.string(),
userId: v.string(),
}),
});chat.tschat.tsimport { v } from "convex/values";
import { mutation, query } from "./_generated/server";
export const sendMessage = mutation({
args: { text: v.string() },
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) {
throw new Error("Unauthenticated call to sendMessage");
}
const { text } = args;
await ctx.db.insert("messages", {
text,
userId: identity.subject,
});
},
});
export const listMessages = query({
args: {},
handler: async (ctx) => {
return await ctx.db.query("messages").order("desc").take(50);
},
});import { v } from "convex/values";
import { mutation, query } from "./_generated/server";
export const sendMessage = mutation({
args: { text: v.string() },
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) {
throw new Error("Unauthenticated call to sendMessage");
}
const { text } = args;
await ctx.db.insert("messages", {
text,
userId: identity.subject,
});
},
});
export const listMessages = query({
args: {},
handler: async (ctx) => {
return await ctx.db.query("messages").order("desc").take(50);
},
});How do I read a user's name when querying the messages via the userId property? For context, I'm using ConvexAuth.
