[Vuejs]-Clear query params in Nuxt Auth on redirect

1๐Ÿ‘

I had a similar situation, using nuxt/auth. When I clicked on logout button I was redirected to login page, but keeping the query parameters from previous page. Like you, I wanted to have it clean.

The idea is to clean the query object from values.

this.$router.replace({ query: [] })
this.$auth.logout()

This clean the parameters and then redirect to login page.

For example: If the url we get is https://myApp/hello?test=here the this.$router.replace({ query: [] }), transform it to this https://myApp/hello and then nuxt/auth logs out and redirect to my login page.

You can check this answer related to vue-router from this post. I took it from here
How to remove query from vue router?

If user is trying to visit a protected page like you mentioned, I think the best way is to use middleware and not this way.

Hope this help!

๐Ÿ‘คycoya

Leave a comment