API endpoint: `/keystone/api/files/create` returns signin page in test files
Closed this issue · 1 comments
radiovisual commented
On Line 31 of test/api-react/file/1-File.js
you make a call to an API endpoint, expecting a json value in return:
api.post('/keystone/api/files/create', {
body: formData,
responseType: 'json',
}
That snippet returns the following error:
xhr:79 Uncaught InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json').
However (in the name of science), if you change
responseType: 'json'
to
responseType: 'text'
then it simply returns the HTML of the login Page, which means the API calls in the test files aren't recognized as authenticated API calls?:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width">
<title>Sign in to Keystone Test</title>
<link rel="stylesheet" href="/keystone/styles/keystone.min.css">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
</head>
<body>
<div id="signin-view"></div>
<script>
var Keystone = {"adminPath":"/keystone","brand":"Keystone Test","csrf":{"header":{"x-csrf-token":"o4mFfdnfU9598c28ae972136be40ed9d7a489d66b1959eab0d"}},"from":"/keystone/api/files/create","userCanAccessKeystone":false};
</script>
<script src="/keystone/js/packages.js"></script>
<script src="/keystone/js/signin.js"></script>
</body>
</html>
JedWatson commented
I've added a check to ensure it redirects you properly when you try and use this interface without being signed in.