Accessing `request` in middleware
Wondering if you can access the
request object in global middleware? I only have the response, along with other things.13 Replies
rising-crimson•6mo ago
on the alpha branch you can for 'request' middlewares
continuing-cyanOP•6mo ago
Is there an example @Manuel Schiller ?
rising-crimson•6mo ago
we have e2e tests in the repo
aside from that, what are you trying to do here?
continuing-cyanOP•6mo ago
need to authenticate my app and store the session in the context or headers so I can reuse it elsewhere
continuing-cyanOP•6mo ago
this is what I hav so far https://pastebin.com/A6GhLVPK
Pastebin
import { RequestedTokenType } from '@shopify/shopify-api'import { ...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
rising-crimson•6mo ago
probably just use getWebRequest then?
https://tanstack.com/start/latest/docs/framework/solid/server-functions#accessing-the-request-context
Server Functions | TanStack Start Solid Docs
What are Server Functions? Server functions allow you to specify logic that can be invoked almost anywhere (even the client), but run only on the server. In fact, they are not so different from an API...
continuing-cyanOP•6mo ago
ah sweet, didn't come across this one, thanks
sensitive-blue•6mo ago
Hey Manuel, right now, getWebRequest doesn't return the expected url when used in a server function inside beforeLoad (https://github.com/TanStack/router/issues/4115). Would you have a workaround in the meantime to get the url pathname?
GitHub
Issues · TanStack/router
🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering. - Issues · TanStack/router
rising-crimson•6mo ago
did you try on the alpha version? it should just work
https://github.com/TanStack/router/discussions/2863#discussioncomment-13104960
sunny-green•6mo ago
It works correctly on the alpha:
rising-crimson•6mo ago
if you could comment that on the GitHub issue please
then I can close that
sunny-green•6mo ago
the OP is about the middleware but @pvman seems to be asking about other thing not related to it,
request.url on a server function ( called from client ) should never actual return the current router url but return the actual URI of the RPC being called, for me thats thats intended behaviour. :p
ill share my opinion there
and on SSR indeed returns the correct url
https://github.com/TanStack/router/issues/4115#issuecomment-2946266243sensitive-blue•6mo ago
Yes exactly, my bad that was a misunderstanding on my part. What I was looking for was , in fact I need to update a cookie at each route change (both initial page load and client side routing) so beforeLoad was needed. But now I have another problem, I get i18n data in the loader and it doesn't fire on client side routing, so I was trying to invalidate the router in beforeLoad. If you have some time here is the link to the issue https://discord.com/channels/719702312431386674/1381935859607011358/1381935859607011358