goClientExample.ts•695 B
import { v } from "convex/values";
import { query } from "./_generated/server";
import { LinkTable } from "./schema";
export const loadOne = query({
args: { normalizedId: v.string(), token: v.string() },
returns: v.union(
v.object({
...LinkTable.validator.fields,
_creationTime: v.number(),
_id: v.id("links"),
}),
v.null(),
),
handler: async (ctx, { normalizedId, token }) => {
if (token === "" || token !== process.env.CONVEX_AUTH_TOKEN) {
throw new Error("Invalid authorization token");
}
return await ctx.db
.query("links")
.withIndex("by_normalizedId", (q) => q.eq("normalizedId", normalizedId))
.first();
},
});