vue-auth: Role Login routing not working

When a user logins successfully i get the following returned data.

{"token":"TOKENKEY","roles":"2"}

My Auth Options Login Data returns both token and roles

var options = {
    token: [{name: 'token', authType: 'bearer', foundIn: 'response'}],
    loginData: {url: 'api/auth', method: 'POST', redirect: 'dashboard'},
    fetchData: {url: 'api/acnt', method: 'GET'},
    rolesVar: 'roles'
};

In My routing i have the following routes

Vue.router.map({
    '/auth/login': {
        component: (resolve) => { require(['./components/views/login.vue'], resolve); }
},

'dashboard': {
    auth: ["1"],
    name:"dashboard",
        component: (resolve) => { require(['./components/views/dashboard.vue'], resolve); }
});

It Doesn’t Route to the dashboard. If I remove auth: [“1”] to auth:true. It works. I am getting the following error

TypeError: this.watch.data is undefined
[Learn More]app.js:15062:58
[vue-router] Uncaught error during transition: 

here is a list of vue resources i am using

"@websanova/vue-auth": "^1.4.0-beta",
    "vue": "^1.0.26",
    "vue-hot-reload-api": "^2.0.6",
    "vue-html-loader": "1.2.3",
    "vue-loader": "8.5.4",
    "vue-mdl": "^0.9.4",
    "vue-resource": "^1.0.3",
    "vue-router": "^0.7.13",
    "vue-strap": "^1.0.11",
    "vue-style-loader": "^1.0.0",
    "vuex": "^1.0.0-rc.2",

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 39 (22 by maintainers)

Most upvoted comments

Finally got it working

"@websanova/vue-auth": "^1.5.1-beta",

needed to change the options to this

/*vue-jwt-auth options */
var options = {
    token: [{request: 'token', response: 'token', authType: 'bearer', foundIn: 'header'}],
    tokenName:'token',
    loginData: {url: 'api/auth', method: 'POST', redirect: 'dashboard'},
    fetchData: {url: 'api/account', method: 'GET' , authType: 'bearer'},
    rolesVar: 'role_id'
};

Laravel Stuff

Auth Controller

   public function login(Request $request)
    {
        if ( ! $token = JWTAuth::attempt($request->only('email', 'password'))) {
            return response([
                'status' => 'error',
                'msg' => 'Invalid credentials.',
                'errors' => [
                    ['field' => 'email', 'rule' => 'auth', 'message' => 'Invalid credentials.'],
                    ['field' => 'password', 'rule' => 'auth', 'message' => 'Invalid credentials.']
                ]
            ], 400);
        }

        return response([
            'status' => 'success'
        ])
            ->header('Authorization', $token);
    }

Account Controller

public function show()
    {
        $user=Auth::user();
        return response([
            'status' => 'success',
            'data' => $user
        ]);

    } 

Routes

  Route::get('account',[
        'middleware' => [
            'jwt.auth'
        ],
        'roles' => ['administrator'],
        'as'=>'account.show',
        'uses' => 'AccountController@show'
    ]);


Route::post('auth',[
        'as'=>'auth.authenticate',
        'uses'=>'AuthController@login',
    ]);