Clever Tagline
Clever Tagline
CCConvex Community
Created by Clever Tagline on 2/26/2025 in #support-community
Sharing an array between Convex and UI?
In the app I'm building for work, I have some data that (ideally) should be shared between Convex and my front-end UI, and I'm not sure how best to accomplish this. As an example, I have a table of contacts. One of the fields in this table is currentState. In the current iteration of our data (Airtable), this field has 23 different options. Rather than keep multiple copies of that list, I'd prefer to just maintain one. One idea that came to mind was to do the following: * Create the array of options in one of my Convex files * Transform that into a validator for use in the schema and appropriate query/mutation functions (using the literals() helper function) * Make a Convex query function that returns the array, to be used in my UI code via useQuery() The first two are the no-brainers. The last item, though, I'm not sure about. Is it bad form to make a query that doesn't actually query the database? Is there a better way to go about this?
10 replies
CCConvex Community
Created by Clever Tagline on 2/21/2025 in #support-community
Advice re: schema design for user-specific role-based properties
I'd love some help brainstorming a solution to an app problem. I'm building a staff dashboard app for work. Users of this app will each have one or more assigned roles. I've got both a users table and a roles table, with the relationship between them already established. No issues there. For some (but not all) roles, there will be custom settings that are exclusive to the role. For example, with the Salesperson role there's a default commission percentage for all salespeople, but an individual salesperson might have a commission that overrides that default. While I could create something like a commission field directly on the users table to store this value, I really don't like to have fields that are only needed in limited use cases. The commission override is just one example of a role-specific setting, and there could be a lot more over time, so I'm trying to think of a more efficient way to save such settings without creating tons of limited-use fields. The idea that I'm leaning toward is to have a multi-purpose roleSettings field that would store an object kinda like this:
{
"roleIdA": {
"roleA_setting1": "value",
"roleA_setting2": "value"
},
"roleIdB": {
"roleB_setting1": "value"
}
}
{
"roleIdA": {
"roleA_setting1": "value",
"roleA_setting2": "value"
},
"roleIdB": {
"roleB_setting1": "value"
}
}
The keys in the main object would be document IDs from the roles table, with the value being an appropriate object containing the available settings for that role. While this feels like the most appropriate way to minimize fields and maximize flexibility, I'm struggling to figure out how to represent that in a schema definition, with an arbitrary number of ID keys, and the value associated with each key being an object with a format specific to that key. Is that even possible with the validator options?
13 replies
CCConvex Community
Created by Clever Tagline on 12/13/2024 in #support-community
Request: Is a document is referenced anywhere else?
I'm building an app for work, and in the front-end there are lots of things that can be added and deleted by the user. In a few cases, I'd like to prevent a given item from being deleted if it's referenced by any other document in any other table. For example, I'm going to be tracking regions where our company has offices, so I made a regions table. There are many things that will reference a specific region—staff, contacts, deals, etc.—and I'd like to prevent a region from being removed if it's referenced by any of those things. What I'd love to have is something like a documentHasReferences helper function: * Its only argument would be the ID of a document ("Target Document") * First the function would determine the table containing that document ("Target Table") * Next it would scour all tables in the project, checking their schemas to find fields that store IDs for the Target Table * If any such fields are found on a table, it would query the table to find any reference to the Target Document in those fields * If a single reference is found on any table, it would return true otherwise it would return false I can obviously create a query that does something similar, but as I continue building the app I'll need to ensure that this query is updated as other tables are added or removed that interact with this region table. Other cases might also come up where something similar would be useful, which would require additional custom queries. The helper function I'm dreaming about wouldn't need any such updates, as it would operate using internal access to a project's tables, their schemas, etc. One function could be used in any number of use cases with any document ID. Is such a function even doable on the Convex end? If not a function, would this be possible as a component?
22 replies
CCConvex Community
Created by Clever Tagline on 11/11/2024 in #show-and-tell
Simple SMS drip campaign driven by Convex
I work for a landscape lighting company, and each person who fills out the request form on our website is sent an immediate SMS response with some questions about what ideas they might have for their project. However, not everyone responds to that request right away. The Christmas season is really busy for us, so in order to save our lone sales exec from following up with each request directly—on top of his other duties, which are plentiful— I was asked to create a SMS drip campaign. Here's how I put it together.
7 replies
CCConvex Community
Created by Clever Tagline on 11/1/2024 in #support-community
Custom function for HTTP action?
I want to use the same authorization process for all HTTP actions in a project rather than including the auth code in each action. I thought a custom action might work, but after reading the Stack post about custom functions, and also reviewing the code in the convex-helpers package, HTTP actions don't appear to be supported. Am I reading that correctly?
19 replies
CCConvex Community
Created by Clever Tagline on 10/14/2024 in #support-community
Using HTTP "Host" header to help validate requests
I'm building some HTTP endpoints for internal use and want to validate requests through them using a token. However, I want to use a different token for prod and dev Convex environments. In looking for a way to identify programmatically which environment is running the function, I noticed that the request's "Host" header matches the root HTTP endpoint URL; e.g. "perfect-ant-202.convex.site". Is it safe to compare against that to determine if the dev or prod URL was called? Is there a chance that this header will change in the future?
8 replies
CCConvex Community
Created by Clever Tagline on 10/8/2024 in #support-community
Tracking time of an API call
I'd like to track the execution time of an API call made in an action, and save the duration into a field. This call could take anywhere from a couple seconds to well over a minute. I'm already creating a record at the start of the action right before calling the API, so my first thought was to just get a new Date instance (or using Date.now()), and then compare the value against the record's creation time. However, then I read this about dates in Convex functions: https://docs.convex.dev/functions/runtimes#using-randomness-and-time-in-queries-and-mutations Is there another way to pull this off and accurately track when I receive the response from the API call?
12 replies
CCConvex Community
Created by Clever Tagline on 10/7/2024 in #support-community
Issues deploying to Fly.io
I'm trying to deploy to Fly.io, but I keep hitting this error:
> [build 5/6] RUN npx convex deploy --cmd 'npm run build':
0.772 ✖ Error: You are not logged in. Log in with `npx convex dev` or set the CONVEX_DEPLOY_KEY environment variable.
> [build 5/6] RUN npx convex deploy --cmd 'npm run build':
0.772 ✖ Error: You are not logged in. Log in with `npx convex dev` or set the CONVEX_DEPLOY_KEY environment variable.
I created a deploy key in my prod settings on the Convex dashboard. I read in the Fly docs about adding build secrets, but frankly the instructions feel incomplete/inaccurate: * It says that I have to first mount the secret via a directive in the Dockerfile. However, after the example code, it says, "This creates a new file when running docker build"—which it doesn't. I had to create that file myself and put the key into it, or else I just got an error that it couldn't find the file. * The docs then say that I need to also pass the key when calling fly deploy, which feels redundant. If the key is in the file and the Dockerfile is configured to read it, why must I also pass it via a flag? Also, that doesn't help with the initial deployment using fly launch. Command-line tools aren't my strong suit, so I'm not sure what else to try.
26 replies
CCConvex Community
Created by Clever Tagline on 10/6/2024 in #support-community
Union from data?
I'm migrating a detailed planning system from Airtable to Convex, and one of the data points on each task is the task type. In the original Airtable version, each type is assigned a color. When saving the data, though, I only want to save the name of the task type, with the color only being rendered inside the app for visual reference. Originally I had designed the table schema with the possible options for the task type like this:
taskType: v.union(
v.literal("Single"),
v.literal("Recurring"),
v.literal("Scheduled"),
v.literal("Sequence"),
v.literal("Interval")
)
taskType: v.union(
v.literal("Single"),
v.literal("Recurring"),
v.literal("Scheduled"),
v.literal("Sequence"),
v.literal("Interval")
)
That's working fine. I'm now at the point in the app design where I want to display a color swatch on each task depending on the task type. What I'd like to do is start with something like this so that I only have to define the names and colors in one place:
export const taskTypeData = [
{ label: "Single", color: "var(--mantine-color-blue-7)" },
{ label: "Recurring", color: "var(--mantine-color-red-9)" },
{ label: "Scheduled", color: "var(--mantine-color-green-9)" },
{ label: "Sequence", color: "var(--mantine-color-yellow-9)" },
{ label: "Interval", color: "var(--mantine-color-gray-6)" },
]
export const taskTypeData = [
{ label: "Single", color: "var(--mantine-color-blue-7)" },
{ label: "Recurring", color: "var(--mantine-color-red-9)" },
{ label: "Scheduled", color: "var(--mantine-color-green-9)" },
{ label: "Sequence", color: "var(--mantine-color-yellow-9)" },
{ label: "Interval", color: "var(--mantine-color-gray-6)" },
]
...and then use the labels to define the schema. However, my initial attempt:
taskType: v.union(taskTypeData.map(t => v.literal(t.label)))
taskType: v.union(taskTypeData.map(t => v.literal(t.label)))
...led to this error:
Argument of type 'VLiteral<string, "required">[]' is not assignable to parameter of type 'Validator<any, "required", any>'
Argument of type 'VLiteral<string, "required">[]' is not assignable to parameter of type 'Validator<any, "required", any>'
I'm still fairly new to TypeScript, so I don't yet understand if/how this could be tweaked to do what I want. Is this even possible?
9 replies
CCConvex Community
Created by Clever Tagline on 10/4/2024 in #support-community
Feature request: Account switching in CLI
Earlier this morning I found a thread where @lee was helping someone with a login-switching problem, and I'm glad I did. I've got both personal and work accounts on Convex, and it looks like I'll be using the solution that Lee shared (forcing the login: npx convex login --force) a lot as I'll be switching between these accounts very frequently on the same system, possibly multiple times a day. Would it be possible to update the CLI tool to a) allow more than one authorized login on the same system, and b) add a login switching feature? Maybe something like npx convex login --switch to bring up a prompt showing all available options, or npx convex login --use [nickname] to immediately change. I feel this could be a really useful feature for many users.
2 replies
CCConvex Community
Created by Clever Tagline on 9/26/2024 in #support-community
Error deploying to Vercel
No description
11 replies
CCConvex Community
Created by Clever Tagline on 9/25/2024 in #support-community
Validate a user during the auth step
I'm working on a personal app (i.e. nobody else should use it but me), and the easiest way I could think of to launch it is to deploy it online (e.g. Vercel) and use auth to prevent anyone but me from using it. I added Convex Auth to the app code yesterday, configured to use GitHub, and that part works fine. Once the auth phase is complete, I can look at the user details, see whether or not it's me, and just not render anything if it's some other GitHub user. However, is there a way to restrict any other GitHub user from even completing the auth phase? For example, GitHub verifies that someone has a GitHub account, but compares that against a list that I provide to only allow select users (e.g. me) to complete the rest of the auth. I'm likely going to face a similar challenge in the future when adding auth to an app that I'll be creating for work. It should only be usable by company employees, and the company emails are all run through a Google workspace, so I was thinking of using Google auth to verify our users and only allow those with emails from our workspace/domain to access the app. However, I have a similar question about a mid-phase verification. For example, the Google auth page loads and a user picks their Google account that they'd like to use to log in. What I'd ideally like to do is prevent the password entry from even appearing if their email isn't on our domain. Is something like that even possible, whether it's with Convex Auth or some other provider like Clerk?
10 replies
CCConvex Community
Created by Clever Tagline on 9/22/2024 in #support-community
How to run multiple local-only apps that use Convex
I'm finally getting my feet wet with Convex, and so far I'm really loving it. Aside from future plans for work-related projects, I would also love to migrate a bunch of personal databases from Airtable and create custom apps for them (probably in Remix, which I'm also learning at the same time). However, these would purely be for my own personal use; i.e. no public hosting. Each app would likely have its own Convex project, but I'd like some of them to be able to talk to each other; e.g. on the splash page for my planning app I'd like to pull a random quote from my quotes database. The thing I'm struggling to figure out is how to best run all of this stuff locally, partly when it comes to launching each app, but also with the aforementioned interactivity in mind. The only idea that's come to mind so far is to possibly use Docker (another tool I'm just getting started with), but even after building a separate image for each app, that would still involve (I think) a bunch of terminal-based steps to get each container running before launching any of the apps. Or maybe there's some aspect of using Docker that I haven't discovered yet that would make this easier? At any rate, whether or not you've gone this route yourself, I'd be grateful for any input on how I might pull this off.
15 replies
CCConvex Community
Created by Clever Tagline on 4/13/2024 in #support-community
Unable to complete OpenAI portion of tutorial: limit supposedly exceeded on brand new account
I'm going through the Convex tutorial, and got to the part where I'm supposed to implement the OpenAI integration. When going to the OpenAI site to create an account, I logged in using my personal Google account instead of creating an account manually. Before creating an API key I had to complete the account verification using my mobile phone number. After doing so, I got a popup with a message about how my phone number was supposedly tied to an existing account, and because of that my free trial was supposedly already used. This was my first time logging into OpenAI, though, so I have no idea how my phone could be tied to an existing account. I'm planning on reaching out to the OpenAI support folks to ask about this. I went ahead and manually triggered the chat function I'd created from the tutorial, but I received a 429 error saying that I'd supposedly exceeded my current quota. :/ I even went back through the usage history in the OpenAI dashboard, but couldn't see any evidence of my supposed usage of the service, so I have no idea how I allegedly exceeded my quota. Have any other users reported this issue? No sure if it's worth adding a comment to the tutorial about this possible problem, but I wanted to at least make someone aware of it.
19 replies