Kepmon
Kepmon
Explore posts from servers
NNuxt
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:
if (to.path === '/dashboard' && userResponse == null) {
return navigateTo(
{
path: '/',
query: {
error: 'true'
}
},
{ redirectCode: 307 }
)
}
if (to.path === '/dashboard' && userResponse == null) {
return navigateTo(
{
path: '/',
query: {
error: 'true'
}
},
{ redirectCode: 307 }
)
}
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