Restrict direct access to NextJS routes

I am writing a user onboarding flow where the whole onboarding flow is about 3 pages, it starts with username, email and password on route 1 (lets say /signup/credentials), full name, other details etc on route 2 (/signup/details) and some last few details on route 3 (/signup/confirm) lets say. On route 3, I have a button which takes the data from all 3 routes, compiles it into some data, and makes the API call to sign up the user. By this logic, I only want to allow client side routing from route 1 to route 2, and client side routing from route 2 to route 3, i.e. users shouldnt be able to go to /signup/confirm route directly. I have 2 questions. Is this a good idea ? 2nd, how do I restrict direct access to these routes in NextJS ? One idea I have in mind is to keep some global state (lets say some boolean set to false initially), and only set it to something other than the default (lets say true) when the previous step is complete, so when user lands on a route directly, we check this state and only show if the state was altered from the default.
2 Replies
Jai
Jai9mo ago
Btw. I dont know if my question made any sense haha. So lemme know if you want me to clarify
ATOMowy_grzyb
ATOMowy_grzyb9mo ago
assuming those are pages, I'd update the user with what page they have finished, and allow them to access page n+1 only if they submitted page n this means you can't really keep aggregating the data client-side and send it once, or at least you have to send a progress update call from each page
Want results from more Discord servers?
Add your server
More Posts
Should I use "use server" directive for database queries```ts "use server" import { db } from "~/server/db"; export async function getArticle(id: string) Is there a way to refactor the query/mutation function to a different file?Basically I'm wondering if it's possible to get the type of the function that's passed into the querI'm a complete React beginner, is this the correct approach for Components?Hello everyone, I am tasked to do some buttons that have both a logo, and text. The logo is supposedHow to keep track of multiple running mutations with same function but different input variables?I have a single mutate function that's basically: const doWork = api.example.doWork.useMutation() Vercel postgres + Prisma migrateI got a super simple setup using Vercel's Postgres services, when running `prisma migrate dev` I do How to simulate Open AI's word by word stream works in the backend?I have a completed string and i want to deliver it word by word instead of dumping the whole string.Clerk and T3 (app router)Does clerk work with T3 app router yethelp interleaving server/client comps in layout?picture attached is more or less what's happening. before RSC, i'd just have a factory (using factoDockerized T3 giving prisma connection errorsHey! So I am running a docker network where I have `srv-cap--kobos-db` as a ready and availble databtrpc fetch failed in server actions: Request body length does not match content-length headerHello guys ! I was trying out the new t3-app boilerplate with the app router and in the example, we