Next.js Discord

Discord Forum

How should I control the flow of the sign-up (user creation/org creation/subscription payment)?

Unanswered
Japanese cockle posted this in #help-forum
Open in Discord
Japanese cockleOP
Hi, I'm trying to get the flow of sign-up users in my saas, I'm using Clerk for auth and LemonSqueezy for payment subscription.

I want to control if the user is created in clerk and my db, if the user has created an org in clerk and my db and if the user has a subscription in my db.

I don't know if I should do it in the middleware.ts or if I should make a provider that wraps the whole app and checks and redirects to login/org creation/payment in case something is missing. Another problem I see using middleware is that I can't seem to connect to the db in there.

3 Replies

Komondor
middleware should have no problem connecting to the DB. What are you trying to do? You mention "control". Are you trying to redirect the user to specific pages depending on if they've created an org, or haven't subscribed?
@Komondor middleware should have no problem connecting to the DB. What are you trying to do? You mention "control". Are you trying to redirect the user to specific pages depending on if they've created an org, or haven't subscribed?
Japanese cockleOP
Yes, if the haven't created an org, I want to show them the /org/create page, after that, if the don't have a subscription i want to redirect them to /billing. For the connecting to the db in the middleware, i tried some time ago and i think it said something about middleware executing on edge, so it can't connect to the db, i'm using prisma btw
Komondor
oh darn sorry I'm not familiar with edge. Seems weird that you wouldn't be able to though