Next.js Discord

Discord Forum

User / Account relationship validation

Unanswered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
Here is my NextJS 14 (app router) current setup. I want to add some logic to my pages to check that the clerk user (can be looked up by user ID in the accounts table) is a part of the account in the current pathname.

User logs in via Clerk (using clerk middleware they have to login)

User is directed to the root page.

The root page has logic to check if the user has an account already, if the user has one it redirects to localhost:3000/${accountId}. If not one is created and then redirected.

The user will always be at the localhost:3000/${accountId} or otherwise redirected

How should I go about adding a check in my page.jsx files to validate that a user is a part of the account in the url PATH? I've already setup some logic in my api route.js files to validate this, but not every page makes a request there and I'd still like to redirect them to make an account if they don't have one. (If they somehow get a url of another account ID for instance). Should I just add a function in each page? the layout?

0 Replies