K
Kinde7mo ago
zor

Should I include user model in database schema? And how to handle users registering their business?

Hi, how should I handle database schema while using Kinde? Should I try for creating user model in my database schema e.g. username email registryDate gotWarnings? If we answer this question and let's say I shouldn't create a user model since I use Kinde, how should I handle the situation users register their restaurants in my app? I'm not trying to ask something unrelated but how that relation works with the Kinde user and restaurant if I create the restaurant model. I use Convex as my Backend and very new to both Kinde and Convex.
No description
9 Replies
zor
zorOP7mo ago
To make your work easier, you can just tell me if this is correct answer or the LLM has hallucinated:
Let's clarify the approach:
1. Kinde and User Management:
No user model needed: Kinde handles user management (registration, login, etc.) and stores user data securely. You don't need to create a separate user model in your Convex database.
Accessing user information: You can access the currently logged-in user's information (e.g., user ID) within Convex functions using Kinde's provided methods or libraries.
2. Restaurant Model in Convex:
Create a Restaurant table: Define a Restaurant table in your Convex schema with relevant fields like:
name (string)
ownerId (string, referencing the Kinde user ID)
address (string)
otherRestaurantDetails (any additional information)
3. Linking Restaurants to Users:
When a user registers a restaurant:
Inside your Convex function handling restaurant registration, retrieve the currently logged-in user's ID using Kinde's methods.
Store this user ID in the ownerId field of the newly created restaurant record in the Restaurant table.
4. Access Control and Data Ownership:
Convex function authorization: Within your Convex functions, you can use the auth object to check the currently logged-in user and their permissions. This allows you to restrict access to restaurant data based on ownership (e.g., only the owner can modify a restaurant's information).
Example Flow:
User logs in using Kinde.
User fills out a form to register their restaurant.
The frontend sends a request to a Next.js API route.
The API route calls a Convex function to handle restaurant registration.
The Convex function:
Retrieves the logged-in user's ID from Kinde.
Creates a new record in the Restaurant table with the restaurant details and sets the ownerId to the retrieved user ID.
Let's clarify the approach:
1. Kinde and User Management:
No user model needed: Kinde handles user management (registration, login, etc.) and stores user data securely. You don't need to create a separate user model in your Convex database.
Accessing user information: You can access the currently logged-in user's information (e.g., user ID) within Convex functions using Kinde's provided methods or libraries.
2. Restaurant Model in Convex:
Create a Restaurant table: Define a Restaurant table in your Convex schema with relevant fields like:
name (string)
ownerId (string, referencing the Kinde user ID)
address (string)
otherRestaurantDetails (any additional information)
3. Linking Restaurants to Users:
When a user registers a restaurant:
Inside your Convex function handling restaurant registration, retrieve the currently logged-in user's ID using Kinde's methods.
Store this user ID in the ownerId field of the newly created restaurant record in the Restaurant table.
4. Access Control and Data Ownership:
Convex function authorization: Within your Convex functions, you can use the auth object to check the currently logged-in user and their permissions. This allows you to restrict access to restaurant data based on ownership (e.g., only the owner can modify a restaurant's information).
Example Flow:
User logs in using Kinde.
User fills out a form to register their restaurant.
The frontend sends a request to a Next.js API route.
The API route calls a Convex function to handle restaurant registration.
The Convex function:
Retrieves the logged-in user's ID from Kinde.
Creates a new record in the Restaurant table with the restaurant details and sets the ownerId to the retrieved user ID.
Claire_Kinde
Claire_Kinde7mo ago
Hi Zor. Our Kinde AI can really only answer questions about Kinde functionality and not about how you need to set things up - so the above does not seem very useful to me either.
I was thinking that you could explore organizations in Kinde to separate users from different restaurants. https://kinde.com/docs/build/multi-tenancy-using-organizations/ Alternatively, you might create a user property called restaurant so you can identify the restaurant associated with each user. Properties let you store any data you need about users. However, you need to build the way to collect that information. https://kinde.com/docs/properties/ Let us know if this information helps and feel free to ask more if you need to. Claire
Kinde Docs
Multi-tenancy using organizations - Build on Kinde - Help center
Our developer tools provide everything you need to get started with Kinde.
Kinde Docs
About properties - Properties - Help center
Our developer tools provide everything you need to get started with Kinde.
zor
zorOP7mo ago
So I should not create a user model in the database schema right? E.g. - User and users restaurants will not have a model but other objects of the restaurants e.g. menu, inventory... will have an model?
zor
zorOP7mo ago
How should I approach this schema with Kinde? I use Convex as Backend and database and I am confused
No description
zor
zorOP7mo ago
Let's say it is an Inventory management system app for restaurants How am I going to keep the relation between models since Kinde's models are not registered in my database schema?
Claire_Kinde
Claire_Kinde7mo ago
Hi Zor, I'm going to get one of our engineers to continue this conversation with you. We will get back to you.
zor
zorOP7mo ago
Okay thanks
Peteswah
Peteswah7mo ago
you could have the kinde users exists on kinde and also in your DB, you will just need to keep them up to date with each other You could have all your user data handled in your DB, and then have a column in your users table kinde_id
zor
zorOP7mo ago
That makes much sense, thank you so much. My questions were all that I think
Want results from more Discord servers?
Add your server