Next.js Discord

Discord Forum

Middleware not check the path after /something/onboarding

Unanswered
Gazami crab posted this in #help-forum
Open in Discord
Avatar
Gazami crabOP
I have this function which should redirect the user if there is auth token and onBoarding is true. P op

    // Check user onBoading status
    if (authToken && authToken?.onboardingDone == true) {
      console.log('admin onbaordin nehat run ')

      const requestedPath = request.nextUrl.pathname;

      const onBoardingRequestedPath = excludedUrlsOnbaording.some((url) =>{
        console.log(url)
        return requestedPath.startsWith(url)
      }
    );

    if (onBoardingRequestedPath) {
      // Redirect the user to a different URL
      return redirectToRoleHome(roles, request);
    }
    }

3 Replies

Avatar
Gazami crabOP
  const excludedUrlsOnbaording = [
    "/entrepreneur/onboarding/",
    "/entrepreneur/common/",
    "/service-provider/onboarding/",
    "/service-provider/common/",
    "/expert/onboarding/",
    "/expert/common/",
    "/investor/onboarding/",
    "/investor/common/",
  ]

This is the array of urls which need to be checked but path after /something/onbaording/ is still accessible even after conditions is match
But when I try to/something/onbaording/ that it does redirect the user when the conditions is true
Avatar
Gazami crabOP
someone please help