Ghost/ghost/admin/mirage/config/config.js
Kevin Ansfield 738823d8f8 Fixed "Authorization Failed" error screens when not logged in
no issue
- `/config/` can only be requested when authenticated
- updated `/config/` mock to look for an Authentication header and return a 403 if it's missing
- updated `ajax` service to add an `Authentication` header when authenticated in testing env (cookies are not present when testing)
- updated `config` service to add `fetchUnauthenticated()` and `fetchAuthenticated()` methods in addition to `.fetch()`
- updated `application` route to only fetch authenticated config when authenticated
- updated `signin` controller to correctly fetch config after sign-in
2019-02-26 10:38:00 +07:00

37 lines
1.0 KiB
JavaScript

import {Response} from 'ember-cli-mirage';
import {isEmpty} from '@ember/utils';
export default function mockConfig(server) {
server.get('/config/', function ({db}, request) {
if (!request.requestHeaders.Authorization) {
return new Response(403, {}, {
errors: [{
type: 'NoPermissionError',
message: 'Authorization failed',
context: 'Unable to determine the authenticated user or integration. Check that cookies are being passed through if using session authentication.'
}]
});
}
if (isEmpty(db.configs)) {
server.loadFixtures('configs');
}
return {
config: db.configs.find(1)
};
});
server.get('/configuration/timezones/', function ({db}) {
if (isEmpty(db.timezones)) {
server.loadFixtures('timezones');
}
return {
configuration: [{
timezones: db.timezones
}]
};
});
}