cancel
Showing results for 
Search instead for 
Did you mean: 

Authentication JSON parse error with ReactJS using Alfresco 5.1.e CE Login REST API

arak
Confirmed Champ
Confirmed Champ

I'm trying to login with my ReactJS app using the login REST API of Alfresco CE 5.1.e, but I have the next error in the console of my browser:

syntax error json parse unexpected end of data at line 1 column 1 of the json data

This error don't happen with Alfresco CE 4.2.e, and I have an application with React Native and the login it's works with 4.2.e and 5.1.e. I have configured CORS in Alfresco. I suppose wich the problem is in ReactJS, i'm use the next code:

api-client.js

function loginAlfresco(user, pass){
   return fetch(alfrescoLocal + "api/login",    {       
      method
: 'post',       
      dataType
: 'json',       
      body
: JSON.stringify({
         
username: user,           
         password
: pass
     
})   
  
})   
   
.then((res) => res.json())
   
.then(data => alert(data))   
   
.catch(error => alert("Error" + error))
};

Login.js

loginAlfresco() {    
   loginAlfresco
(this.state.username, this.state.password)
   
.then((data) => this.setState({ticket: data}))
   .
catch((error) => alert(error))
};

The JSON sended is:

{
   "username":"user",  
   
"password":"12345"
}

Any idea?

2 REPLIES 2

mehe
Elite Collaborator
Elite Collaborator

Has it really worked this way? I don't understand your login.js, but I'm not too experienced in react.

Looks like there is some asynchrony problem. Have you tried to console.log your function parameters before calling?

I had the same error in angular programming, when some variables were not valued as expected. 

arak
Confirmed Champ
Confirmed Champ

Hi Martin,

Thanks for your reply, and now it works.

The problem was in the Alfresco CORS configuration, I change the "cors-filter-1.9.3.jar" library located in the "tomcat/webapps/alfresco/WEB-INF/lib" folder to a newer version "cors-filter-2.4.jar ", and it was solved.

Greetings,

Pablo Arak.