catmal
catmal

Reputation: 1758

Vue router Guard exclude to path with token

I have implemented verification email in my app. After signup the user gets an url to verify email such as:

http://localhost:8080/verify_email/xdGCmMGz6LrBv0s_97gDvQ

I have a Router Guard in place with this condition:

else if (store.state.signedIn && !store.state.currentUser.email_confirmed && to.path !== '/warning_verify_email' && to.path !== '/verify_email/:token') next('/warning_verify_email')

route /warning_verify_email is a component the just gives a warning to check email and verify before proceeding.

The problem I am having is:

to.path !== '/verify_email/:token'

which should not make

http://localhost:8080/verify_email/xdGCmMGz6LrBv0s_97gDvQ

redirect to

/warning_verify_email

But it does.

In routes, path: '/verify_email/:token' works. So I was assuming it would have worked in the guard too. But it doesn't.

How can I fix?

Upvotes: 0

Views: 339

Answers (1)

Steven B.
Steven B.

Reputation: 9362

Your issue is probably your condition. to.path is the actual route not the definition, so in your example to.path will be '/verify_email/xdGCmMGz6LrBv0s_97gDvQ'. You need to check to.matched instead:

const isVerifyRoute = to.matched.some(route => route.path === '/verify_email/:token');

Upvotes: 1

Related Questions