Kepmon
Explore posts from serversNNuxt
β’Created by Kepmon on 3/26/2024 in #βγ»help
How to check on a client side that a user was redirected from middleware?
You're still probably a more experienced user than I am π
I implemented this query param as you suggested previously. I had some issues afterwards with making it disappear after the page reload and so on, but ultimately I made it work and I'm almost happy with the solution π
So thank you for the idea π
Regarding the
useState
composable... I didn't know about its existance so thank you again for informing me on that. Though, I was playing around with it for a short while and - in my scenario - it kept returning the default value, even though I'd changed it in middleware.
So, I started reading more about it and I found this thread: https://github.com/nuxt/nuxt/issues/22668 that seems to explain why it wouldn't work for my use case.
But, overall, it seems like a really handy thing and I already have another possible use case for it, so I'm happy you pointed it out to me π
7 replies
NNuxt
β’Created by Kepmon on 3/26/2024 in #βγ»help
How to check on a client side that a user was redirected from middleware?
Hmm... so, I ended up with code like this:
and... works in Edge and Chrome, doesn't work in Firefox (I always say we should immediately stop supporting this stupid browser but no one would listen to me π€·ββοΈ). Unless I did something wrong (that's why the code). Though, this doesn't change my opinion on Firefox π
Also, I checked the
Network
tab and it seems like Firefox thinks the error code for the /dashboard
path is 301, whereas the Nuxt docs specifically say it's 302 (by default) and I specifically set 307, so....
I was thinking about your idea before but I refrained from implementing it because in general I don't like this error=true
being in my address bar. And seriously, I thought that I'm just stupid and there was a simple solution to my issue. But, while talking to you, I'm starting to think that maybe this time this is not really the case...
So... I guess, I'm going to stick to it and maybe I'll find another one in the future. Thank you for your assistance, it was really helpful π7 replies
NNuxt
β’Created by Kepmon on 3/26/2024 in #βγ»help
How to check on a client side that a user was redirected from middleware?
I didn't know about the
redirectFrom
param, so thank you for letting me know.
Unfortunately, I'm afraid it wouldn't work that easily. I played around with it a bit and it keeps returning undefined
. Then I found this thread: https://github.com/nuxt/nuxt/issues/15146 on Github issues that seems to explain why it wouldn't work.7 replies