[Vuejs]-How to pass the user id along with JWT tokens in local storage

3👍

Make a new function in your controller below login function.

public function user_details(Request $request){

    try {
        $this->jsondata = JWTAuth::authenticate($request->token);
        $this->message = 'User details fetched.';
        $this->status = true;
    } catch (JWTException $e) {
        $this->status = false;
        $this->message = 'Error';
    }

    return response()->json([
        'status'    => $this->status,
        'data'      => $this->jsondata,
        'message'   => $this->message
    ]);
}

Don’t save user_id in browser’s local storage as it will be a major security issue. Use this webservice to get any user’s details via generated token.

Leave a comment