Ghost/ghost/admin/app/routes/site.js
Kevin Ansfield 06cb0bd14e Allowed "view site" request to save cookies in cross-origin requests
no issue

- adds `credentials: 'include'` option to `fetch()` which instructs browsers to save cookies in the POST response in cross-origin requests (default is `'same-origin'`)
2019-09-09 17:01:26 +01:00

41 lines
1.1 KiB
JavaScript

import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import fetch from 'fetch';
import {inject as service} from '@ember/service';
export default AuthenticatedRoute.extend({
config: service(),
settings: service(),
ui: service(),
_hasLoggedIn: false,
model() {
return (new Date()).valueOf();
},
afterModel() {
if (this.settings.get('isPrivate') && !this._hasLoggedIn) {
let privateLoginUrl = `${this.config.get('blogUrl')}/private/?r=%2F`;
return fetch(privateLoginUrl, {
method: 'POST',
mode: 'cors',
redirect: 'manual',
credentials: 'include',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `password=${this.settings.get('password')}`
}).then(() => {
this._hasLoggedIn = true;
});
}
},
buildRouteInfoMetadata() {
return {
titleToken: 'Site'
};
}
});