1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/routes/site.js
Kevin Ansfield 69c3c4af11 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'
};
}
});