entropy
entropy
CCConvex Community
Created by entropy on 12/11/2024 in #support-community
Next build error when ran in github action
Hello, I'm trying to create a CI workflow for my nextjs website. The problem is that I keep getting a build error from convex when running my build step. I don't have this error when I run bun run build locally though.
Error: No address provided to ConvexReactClient.
If trying to deploy to production, make sure to follow all the instructions found at https://docs.convex.dev/production/hosting/
Error: No address provided to ConvexReactClient.
If trying to deploy to production, make sure to follow all the instructions found at https://docs.convex.dev/production/hosting/
8 replies
CCConvex Community
Created by entropy on 12/3/2024 in #support-community
Calculating average rating across a large dataset
Hello! I'm currently looking to build a feature that shows the average rating of a show based on entry logged by users. This is my first time approaching something like this Convex. I was wondering if there were any recommended solutions? I was looking into the Aggregate convex component to potential solve my problem. The only issue I've have with that approach is that a user can log an entry without rating it, but the sameValue does not accept undefined.
export const animeStatsByEntry = new TableAggregate<{
Namespace: Id<'anime'>
Key: null
DataModel: DataModel
TableName: 'anime_entries'
}>(components.aggregateByAnime, {
namespace: doc => doc.animeId,
sortKey: _ => null,
// TODO: This needs to ignore undefined values instead of setting them to 0
sumValue: doc => doc.rating ?? 0
})
export const animeStatsByEntry = new TableAggregate<{
Namespace: Id<'anime'>
Key: null
DataModel: DataModel
TableName: 'anime_entries'
}>(components.aggregateByAnime, {
namespace: doc => doc.animeId,
sortKey: _ => null,
// TODO: This needs to ignore undefined values instead of setting them to 0
sumValue: doc => doc.rating ?? 0
})
6 replies
CCConvex Community
Created by entropy on 11/29/2024 in #support-community
useQuery different return types
Hello, I'm fetching data with useQuery and for some reason it has two different return types. In one component it returns an object with the data, error, etc properties while in the other it only returns the data. returns entry type | null | undefined
const entry = useQuery(api.functions.anime_entries.authSingleById, {
id: media._id
})
const entry = useQuery(api.functions.anime_entries.authSingleById, {
id: media._id
})
returns an object with data about the query as well
const { data: lists, error: listError } = useQuery(
api.functions.lists.authAll,
{}
)
const { data: lists, error: listError } = useQuery(
api.functions.lists.authAll,
{}
)
9 replies
CCConvex Community
Created by entropy on 8/25/2024 in #support-community
Best way of querying documents when using Clerk
Hello! I'm currently working on a project that uses both Convex and Clerk together. I've been running into some issues with consistency within my backend when it comes to query documents by id and wanted to see if anyone had advice. The problem is that it's easy and convenient to query by a user's Clerk id, but I lose the type safety of the _id prop. It also leads to weird situations when creating relationships between tables. Should I just my me query function (returns user info protected by auth RLS) every time I want to query with a user id or is using the clerkId as the primary way of fetching a document a ok practice? me function
export const me = authRLSQuery({
handler: async ctx => {
const user = await getUser(ctx, ctx.identity.subject)
if (!user) {
throw new ConvexError({ message: 'No user found for this identifier' })
}
return user
}
})
export const me = authRLSQuery({
handler: async ctx => {
const user = await getUser(ctx, ctx.identity.subject)
if (!user) {
throw new ConvexError({ message: 'No user found for this identifier' })
}
return user
}
})
utils
export async function getUser(ctx: QueryCtx | MutationCtx, clerkId: string) {
const user = await ctx.db
.query('users')
.withIndex('by_clerkId', q => q.eq('clerkId', clerkId))
.first()
return user
}
export const authRLSQuery = customQuery(query, {
args: {},
input: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity()
if (!identity) {
throw new ConvexError({
code: 'UNAUTHORIZED',
message: 'Sorry, you must be logged in to perform this action'
})
}

const db = wrapDatabaseReader({ identity }, ctx.db, {
users: {
read: async (ctx, user) => ctx.identity.subject === user.clerkId
}
})
return { ctx: { ...ctx, db, identity }, args }
}
})
export async function getUser(ctx: QueryCtx | MutationCtx, clerkId: string) {
const user = await ctx.db
.query('users')
.withIndex('by_clerkId', q => q.eq('clerkId', clerkId))
.first()
return user
}
export const authRLSQuery = customQuery(query, {
args: {},
input: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity()
if (!identity) {
throw new ConvexError({
code: 'UNAUTHORIZED',
message: 'Sorry, you must be logged in to perform this action'
})
}

const db = wrapDatabaseReader({ identity }, ctx.db, {
users: {
read: async (ctx, user) => ctx.identity.subject === user.clerkId
}
})
return { ctx: { ...ctx, db, identity }, args }
}
})
8 replies
CCConvex Community
Created by entropy on 7/8/2024 in #support-community
ip whitelist with httpRouter
Hello, I'm currently using the httpRouter with Clerk webhooks to sync events with convex. I was wondering if there was a easy way to setup an ip whitelist so any requests that aren't from a specific ip list are dropped?
9 replies
CCConvex Community
Created by entropy on 5/29/2024 in #support-community
Implementing non OpenID custom auth
Hello, I have a website that requires dual auth provider sign ins for a valid session. Previous I would do this with supabase by using their JWT secret to sign my session cookie. This allowed supabase auth to work with my custom authenication system. I was wondering if there was a similar way to do this with Convex?
5 replies
CCConvex Community
Created by entropy on 5/16/2024 in #support-community
preloaded data with paginated query
Hello, I was wondering if there was an official way of preload loading data for a paginated query in nextjs? With regular queries I can just use the usePreloadedQuery() hook, but I don't see an equivalent for paginated queries.
9 replies
CCConvex Community
Created by entropy on 5/9/2024 in #support-community
Failed to load url with convex-test
No description
28 replies
CCConvex Community
Created by entropy on 5/6/2024 in #support-community
Adding typing to ConvexError data field without casting everytime
Hello! I was using ConvexError and following the docs on adding custom data to the data field of ConvexError. The docs recommended casting for getting the correct typings, but I feel this would be a bit cumbersome. Is there any better way to do this?
5 replies
CCConvex Community
Created by entropy on 5/1/2024 in #support-community
Is possible to export schema from nested folder?
No description
31 replies