anchor.diff:  %% @end
   -spec delete_resource(ReqData::tuple(), State::string()) -> {string(), tuple(), string()}.
   delete_resource(ReqData, State) ->
  -    Id = id_from_path(ReqData),
  -    case delete_streams_with_user_id(Id) of
  -        {error, {Code, Body}} ->
  -            ErrorString = api_help:generate_error(Body, Code),
  -            {{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
  -        {ok} ->
  -            case erlastic_search:delete_doc(?INDEX,"user", Id) of
  +    case analyse_token("access_token", ReqData) of
  +        {error, Msg} -> {{halt, 403}, wrq:set_resp_body(Msg, ReqData), State};
  +        {ok, Token} ->
  +            % {true, wrq:set_resp_body(Token, ReqData), State}
  +            Id = id_from_path(ReqData),
  +            case delete_streams_with_user_id(Id) of
                   {error, {Code, Body}} ->
                       ErrorString = api_help:generate_error(Body, Code),
                       {{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
  -                {ok,List} ->
  -                    {true,wrq:set_resp_body(lib_json:encode(List),ReqData),State}
  +                {ok} ->
  +                    case erlastic_search:delete_doc(?INDEX,"user", Id) of
  +                        {error, {Code, Body}} ->
  +                            ErrorString = api_help:generate_error(Body, Code),
  +                            {{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
  +                        {ok,List} ->
  +                            {true,wrq:set_resp_body(lib_json:encode(List),ReqData),State}
  +                    end
               end
       end.
   
  
positive.code:             case api_help:is_auth_redirect(ReqData) of
                  true  -> process_auth_redirect(ReqData, State);
                  false ->
                      case analyse_token(ReqData, "refresh_token") of
                          % {ok, RefTok} ->
                          {ok, _} ->
                              case api_help:is_search(ReqData) of
  
negative.code: 
                          {error, Msg} ->
                              % {true, wrq:set_resp_body("Msg", ReqData), State}
                              case analyse_token("access_token", ReqData) of
                                  {ok, JSON} ->
                                      % {true, wrq:set_resp_body(JSON, ReqData), State}
  
                                      case api_help:is_search(ReqData) of
                                          true  -> process_search(ReqData,State, get);
                                          false -> get_user_model(ReqData, State)
                                      end;
                                  _ ->
                                      Msg = "Not possible to perform the request. access_token mismatches",
                                      {{halt, 403}, wrq:set_resp_body(Msg, ReqData), State}
                              end
                      end
              end
      end.
  
  
  -spec analyse_token(TokenName::string(), ReqData::tuple()) -> tuple().
  analyse_token(TokenName, ReqData) ->
      case wrq:get_qs_value(TokenName, ReqData) of
          undefined ->
              case wrq:get_req_header(TokenName, ReqData) of
                  undefined -> {error, "Not possible to perform the request. Missing " ++ TokenName};
                  TokenVal  -> get_user_by_token(TokenName, TokenVal)
              end;
          TokenValue -> get_user_by_token(TokenName, TokenValue)
      end.
  
  