DaReal
DaReal
CCConvex Community
Created by DaReal on 7/19/2024 in #support-community
Convex Queries In Server Components
I have a route ("/users/[userId]") and i want to fetch user info from the database by using the Convex query hook "useQuery" and also supply the data through a global state using zustand to child routes. However, i can only use the Convex hook in a client component. How do you suggest i implement this because i dont want to make the whole layout a client component.
3 replies
CCConvex Community
Created by DaReal on 7/16/2024 in #support-community
Help with 3rd party api call in Actions
So i am trying to reach clerk's backend api in a convex action. The action needs a node package so i am using the "use node" at the top of the document where i am defining the action. So the issue now is, the call works just fine but when i return the result of the call, Convex throws an error. However, when i console log the result of the call, it returns the data just as expected. The error i am getting is as follows:
13 replies
CCConvex Community
Created by DaReal on 7/15/2024 in #support-community
Session Handling With Clerk
I am sure there is a solution for this but i don't know how to go about it. I am not currently doing any session handling in my project but I need two use cases where I believe i need to work with sessions. 1. I want to be able to know the number of currently active/online users by finding out the users who currently have an active session. Not sure if this is the right approach but i am open to ideas. 2. In clerk, i set a session lifetime to 5 minutes. If a user is currently on the site when the 5 minutes session lifetime counts down, the user is meant to be redirected to the login screen or the homepage but instead it throws an error. I am not sure how i should go about these but the only thing i noticed so far is that Clerk has webhook event triggers for sessions when they are created, ended, revoked or timed out. But i don't know if this is the right approach because i also saw a Convex stack article on session tracking. I will really appreciate the help. Thanks in advance
11 replies
CCConvex Community
Created by DaReal on 7/11/2024 in #support-community
Weekly and Monthly Cron Jobs
I just want to clarify the schedule parameters for the weekly cron job. I want the cron job to run on the Monday of every week by 12am. How do i go about that? The weekly cron job code snippet in the doc didnt include the day key and value but the monthly includes it. crons.monthly( "Bill customers at ", { hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific) minuteUTC: 30, day: 1, }, api.billing.billCustomers ) crons.weekly( "Weekly re-engagement email", { hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific) minuteUTC: 30, }, api.emails.send )
3 replies
CCConvex Community
Created by DaReal on 6/3/2024 in #support-community
Convex Clerk Authentication
Hello guys! I have an issue with my Convex-Clerk Authentication. The issue is obvious during the sign in and sign up process when sending verification codes. The page loads twice therefore causing the otp to be sent 2x during sign-in and sign-up. This behaviour also occurs when a form is submitted. It reloads the page. Below is my code for ConvexClerkProvider.tsx "use client"; import Loading from "@/app/components/auth/Loading"; import { ClerkProvider, useAuth } from "@clerk/clerk-react"; import { AuthLoading, Authenticated, ConvexReactClient, Unauthenticated, } from "convex/react"; import { ConvexProviderWithClerk } from "convex/react-clerk"; type ConvexClerkProviderProps = { children: React.ReactNode; }; const clerkPublishableKey = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY; if (!clerkPublishableKey) { throw new Error("Missing Clerk Publishable Key"); } const convexUrl = process.env.NEXT_PUBLIC_CONVEX_URL!; const convex = new ConvexReactClient(convexUrl); const ConvexClerkProvider = ({ children }: ConvexClerkProviderProps) => { return ( <ClerkProvider publishableKey={clerkPublishableKey}> <ConvexProviderWithClerk client={convex} useAuth={useAuth}> <AuthLoading> <Loading /> </AuthLoading> <Authenticated>{children}</Authenticated> <Unauthenticated>{children}</Unauthenticated> </ConvexProviderWithClerk> </ClerkProvider> ); }; export default ConvexClerkProvider; Below is my layout structure: export default function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { return ( <html lang="en"> <body className={${inter.className}}> <ConvexClerkProvider> {children} <Toaster /> </ConvexClerkProvider> </body> </html> ); } Thanks in advance.
21 replies
CCConvex Community
Created by DaReal on 5/19/2024 in #support-community
Difference Between .get and .query and Best Use Case
Hello! I am trying to understand the difference between the ctx.db.get and the ctx.db.query I have read the docs but i am a bit confused. I also think they can be used to perform the same operation in some cases. However, I would like a good explanation and best use case for each. Thanks in advance! ☺️
5 replies
CCConvex Community
Created by DaReal on 5/16/2024 in #support-community
Errors Using Queries in Client
No description
12 replies
CCConvex Community
Created by DaReal on 5/15/2024 in #support-community
Deleting Document and Its Referenced Documents
Hello Support, I would like to know if it is possible and how i can delete a document and also all documents where it has a relationship with the document i am deleting. So i have a "Users" and "Transactions" table (there are more but this is for simplicity sake). I want to delete a specific document/user from the "Users" table and I also want to be able to delete all documents in the "Transactions" table that has a relation ship with the specific user i am deleting. I was thinking of searching for all documents that has the id referenced in the "Transactions" table using the Index but i was wondering if there is a better approach. I hope you understand. Thanks in advance.
24 replies
CCConvex Community
Created by DaReal on 5/15/2024 in #support-community
Handling Multiple Mutations In An Action
Hello Support, I am using clerk with my Convex project. When a user signs up, i listen to the event using webhook and insert the user into the database. However, i also need to set some defaults records and fields for the user which will be added. I am planning to use actions to run multiple mutations that inserts the user into the db and also another mutation that sets default values for the field. I am wondering how the error handling works in this case. Assuming the user is added and for some reason the fields are not set, how will i be able to handle such situations efficiently. I am also open to better implementations on how to properly implement this. Thanks in advance.
14 replies
CCConvex Community
Created by DaReal on 5/9/2024 in #support-community
Clerk + Convex Identifier Recommendation
Hello! I have a question regarding an identifier for Clerk in the database. Clerk has 2 different ways of identifying users and it doesn't seem to be consistent in a way. When using the currentUser() hook, it returns tokenIdentifier and subject. The tokenIdentifier is a combination of the clerk url and the subject. However, when getting data using Clerk webhook, it returns a unique identifier named "id" which is the same as the value of the subject identifier. My question now is: Which of this is recommended to use as a unique identifier in my Convex database so I can easily map Clerk users to their data in the database. I was thinking of storing both the tokenIdentifier and subject/id but it might not be a good practice. Lastly, the reason why i am asking this is because when performing queries or mutations on the database, i will mostly need to locate a specific user in the DB and it must be done using an identifier. Thanks in advance.
3 replies