hyperzone
hyperzone•12mo ago

Linking teams with Clerk organizations

I've looked at the saas-starter https://github.com/xixixao/saas-starter, and I'm looking to do something similiar and I was wondering, should I create a Clerk organization for each team? Instead of handling the invites by myself like in the example I could use their org features one of them being the invites and etc Are there downsides to this approach?
6 Replies
hyperzone
hyperzoneOP•12mo ago
Also I'm trying out ents and I'm getting this error:
Uncaught Error: Missing inverse edge in table "members" for edge "members" in table "businesses"
Uncaught Error: Missing inverse edge in table "members" for edge "members" in table "businesses"
for this schema:
const schema = defineEntSchema(
{
businesses: defineEnt({
name: v.string(),
organizationId: v.string(),
image: v.string(),
ownerUserId: v.string(),
})
.field("slug", v.string(), { unique: true })
.edges("members", { ref: true })
.deletion("scheduled", { delayMs: BUSINESS_DELETION_DELAY_MS }),
users: defineEnt({
// this is UserJSON from @clerk/backend
clerkUser: v.any(),
})
.index("by_clerk_id", ["clerkUser.id"])
.edges("members", { ref: true, deletion: "soft" })
.deletion("soft"),
members: defineEnt({})
.edge("business")
.edge("user")
.index("businessUser", ["businessId", "userId"])
.deletion("soft"),
},
{ schemaValidation: true }
);
const schema = defineEntSchema(
{
businesses: defineEnt({
name: v.string(),
organizationId: v.string(),
image: v.string(),
ownerUserId: v.string(),
})
.field("slug", v.string(), { unique: true })
.edges("members", { ref: true })
.deletion("scheduled", { delayMs: BUSINESS_DELETION_DELAY_MS }),
users: defineEnt({
// this is UserJSON from @clerk/backend
clerkUser: v.any(),
})
.index("by_clerk_id", ["clerkUser.id"])
.edges("members", { ref: true, deletion: "soft" })
.deletion("soft"),
members: defineEnt({})
.edge("business")
.edge("user")
.index("businessUser", ["businessId", "userId"])
.deletion("soft"),
},
{ schemaValidation: true }
);
I built this schema following the saas starter and for some reason this error pops up
sshader
sshader•12mo ago
re: the ent schema error, I might be wrong here, but I think ents assumes you can pluralize an edge by adding an s at the end, so .edge("user") is an edge to "users" but .edge("business") gets interpreted as an edge to "businesss" (just adding an s at the end). I'm not sure what the best way to work around this would be, but I'd maybe try out edge("businesse") (which will get interpreted as an edge to "businesses") to see if that might be the issue
hyperzone
hyperzoneOP•12mo ago
thanks! I spent so much time trying to figure this out lol I might be wrong, but I think it's not documented in the ent docs. I read it a few times and didn't see any mention of pluralization it's also the same with category -> categorie
Michal Srb
Michal Srb•12mo ago
Sorry about that, I'll update the Ent docs You can use
.edge("business", {field: "businessId", to: "businesses"})
.edge("business", {field: "businessId", to: "businesses"})
to control the naming.
Michal Srb
Michal Srb•12mo ago
To your original question, using Clerk is a different approach that you can certainly take. Use webhooks to sync the Clerk data to Convex: https://www.convex.dev/templates/clerk
Templates
The backend application platform with everything you need to build your product.
hyperzone
hyperzoneOP•12mo ago
thanks! really like Ent thanks for your work 🙂

Did you find this page helpful?