I am trying to call my restapi (created with java spring) to authorize the user in vuejs. To do that I call an HTTP request using fetch. This works fine in chrome and firefox, however not in Opera andEdge.
This is the code I am executing in the mounted() method:
fetch(
'http://localhost:8083/oauth2/user',
{
method: 'GET',
headers: {
'Authorization': localStorage.accesstoken,
'Accept': 'application/json',
'Content-Type': 'application/json',
},
}
)
.then(res => {
console.log("Status: " + res.status)
if (res.status === 200) {
return res.json();
} else {
console.log(res.text())
}
}
)
.then(res => {
console.log("jsondata: " + res)
}
)
.catch((e) => {
console.log(e)
}
)
Running in Opera:
Status: 200
SyntaxError: Unexpected end of JSON input
Response: "This request has no response data available."
Running in Chrome
Status: 200
jsondata: [object Object]
Response: <correct JSON object it's suppose to have>
This is the java spring boot I call:
@CrossOrigin
@GetMapping("/oauth2/user")
ResponseEntity<String> getUserInfo(@RequestHeader("Authorization") String authentication){
try {
PrimeUser user = authenticateUser(authentication);
assert user != null;
return ResponseEntity.ok()
.body(new Gson().toJson(user));
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.internalServerError()
.body(e.getMessage());
}
}