Skip to content

Document vs Fetch redirect in middleware #61

Answered by rphlmr
jezikk asked this question in Q&A
Discussion options

You must be logged in to vote

Arg, this is really not a good developer experience.
Maybe we could check the the request path.

  if (!tokens) {
    const url = await getAuthorizationUrl(c, session, options);
    
   if (c.req.path.includes(".data")) {
      return reactRouterRedirect(url);
    } else {
      return c.redirect(url);
    }
  }

The idea is to send back what a .data fetch expects (Single fetch) or use a normal redirect.

It should not happen in production mode, but it should not happen at all. In dev mode, Vite is loading the route even if the browser has started a redirect :/

Thanks for your feedback 🙏

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@jezikk
Comment options

@rphlmr
Comment options

Answer selected by jezikk
@jezikk
Comment options

@rphlmr
Comment options

@rphlmr
Comment options

@jezikk
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants