Next.js Discord

Discord Forum

Middleware not check the path after /something/onboarding

Gazami crab posted this in #help-forum
Open in Discord
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) =>{
        return requestedPath.startsWith(url)

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

3 Replies

Gazami crabOP
  const excludedUrlsOnbaording = [

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
Gazami crabOP
someone please help