export const userAction = customAction(
action,
{
args: {
userId: v.optional(v.id("users")),
},
input: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) {
throw new Error("Called without authentication present");
}
const user = await ctx.runQuery(internal.users.getUserIdentity, {
tokenIdentifier: identity.tokenIdentifier,
});
if (!user) throw new Error("Authentication required");
return {
ctx: { user },
args,
// This was added and removed, either way i get the same error.
onSuccess: ({ result }) => {
console.info(`Action for user ${user.name} returned:`, result);
}
};
},
}
);
export const getUserIdentity = internalQuery({
args: {
tokenIdentifier: v.string(),
},
handler: async (ctx, { tokenIdentifier }) =>
await ctx.db
.query("users")
.withIndex("by_token", (q) => q.eq("tokenIdentifier", tokenIdentifier))
.unique(),
});
export const userAction = customAction(
action,
{
args: {
userId: v.optional(v.id("users")),
},
input: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) {
throw new Error("Called without authentication present");
}
const user = await ctx.runQuery(internal.users.getUserIdentity, {
tokenIdentifier: identity.tokenIdentifier,
});
if (!user) throw new Error("Authentication required");
return {
ctx: { user },
args,
// This was added and removed, either way i get the same error.
onSuccess: ({ result }) => {
console.info(`Action for user ${user.name} returned:`, result);
}
};
},
}
);
export const getUserIdentity = internalQuery({
args: {
tokenIdentifier: v.string(),
},
handler: async (ctx, { tokenIdentifier }) =>
await ctx.db
.query("users")
.withIndex("by_token", (q) => q.eq("tokenIdentifier", tokenIdentifier))
.unique(),
});