Force user to a page after sign-in and user that already log-in before

Viewed 37

I currently have a service authentication up and running (using jwt to auth).

I'm working on a quiz service that force user to create some required information and force them to take a quiz to understand how to use our tool.

Because lacking of Frontend exp, I'm wondering how this quiz service will integrate with the auth service

Right now, for Backend side during auth service I will give them back the permission in the token if I call the function to check if the user pass the test & have a profile created. Otherwise I give them back the token with permission = []

But for the Frontend side, what is the solution to re-direct use to Quiz page (after sign-in and what about user that already log-in before)

1 Answers

check this documentation programatic navigation

once authenticated redirect the user back using [vue2 code]

this.$router.push({name:'Quiz',params:{id:this.$route.query.next})

In the authentication page you may pass the quiz link as next query parameter eg

example.com/login?next=< quizID >

Navigation guard documentation You can use route guards to redirect unauthenticated users to the login page, do remember to pass the quiz id as a query parameter.

your guard will be similar to this

router.beforeEach((to, from, next) => {
  if (to.name === 'Quiz' && !isAuthenticated) next({ name: 'Login', query: { next: to.params.quizID }})
  else next()
})

This was assuming you have set your routes has a route named Quiz and takes :id and a route named login, similar to this.

     {
    path: '/quiz/:id',
    name: 'Quiz',
    .....
  },
  {
    path: '/login',
    name: 'Login',
    ......
  },

Alternatively, you could have set up a dialog box on the quiz page that handles authication.

Related