mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Skipped waiting for admin authentication
fixes https://github.com/TryGhost/Team/issues/1700 - Admin authentication requests are non blocking now
This commit is contained in:
parent
a5af3f47ce
commit
8d41ec360b
2 changed files with 36 additions and 17 deletions
|
@ -60,6 +60,8 @@ export default class App extends React.Component {
|
||||||
popup: null,
|
popup: null,
|
||||||
accentColor: props.accentColor
|
accentColor: props.accentColor
|
||||||
};
|
};
|
||||||
|
this.adminApi = null;
|
||||||
|
this.GhostApi = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initialize comments setup on load, fetch data and setup state*/
|
/** Initialize comments setup on load, fetch data and setup state*/
|
||||||
|
@ -68,25 +70,10 @@ export default class App extends React.Component {
|
||||||
// Fetch data from API, links, preview, dev sources
|
// Fetch data from API, links, preview, dev sources
|
||||||
const {site, member} = await this.fetchApiData();
|
const {site, member} = await this.fetchApiData();
|
||||||
const {comments, pagination} = await this.fetchComments();
|
const {comments, pagination} = await this.fetchComments();
|
||||||
this.adminApi = this.setupAdminAPI();
|
|
||||||
|
|
||||||
let admin = null;
|
|
||||||
try {
|
|
||||||
admin = await this.adminApi.getUser();
|
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
|
||||||
console.log(admin);
|
|
||||||
/* eslint-enable no-console */
|
|
||||||
} catch (e) {
|
|
||||||
// Loading of admin failed. Could be not signed in, or a different error (not important)
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
site,
|
site,
|
||||||
member,
|
member,
|
||||||
admin,
|
|
||||||
action: 'init:success',
|
action: 'init:success',
|
||||||
initStatus: 'success',
|
initStatus: 'success',
|
||||||
comments,
|
comments,
|
||||||
|
@ -105,6 +92,34 @@ export default class App extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async initAdminAuth() {
|
||||||
|
try {
|
||||||
|
this.adminApi = this.setupAdminAPI();
|
||||||
|
|
||||||
|
let admin = null;
|
||||||
|
try {
|
||||||
|
admin = await this.adminApi.getUser();
|
||||||
|
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.log(admin);
|
||||||
|
/* eslint-enable no-console */
|
||||||
|
} catch (e) {
|
||||||
|
// Loading of admin failed. Could be not signed in, or a different error (not important)
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn(`[Comments] Failed to fetch current admin user:`, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
admin
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setState(state);
|
||||||
|
} catch (e) {
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.error(`[Comments] Failed to initialize admin authentication:`, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Handle actions from across App and update App state */
|
/** Handle actions from across App and update App state */
|
||||||
async dispatchAction(action, data) {
|
async dispatchAction(action, data) {
|
||||||
clearTimeout(this.timeoutId);
|
clearTimeout(this.timeoutId);
|
||||||
|
@ -287,6 +302,10 @@ export default class App extends React.Component {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.initSetup();
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
/**Clear timeouts and event listeners on unmount */
|
/**Clear timeouts and event listeners on unmount */
|
||||||
clearTimeout(this.timeoutId);
|
clearTimeout(this.timeoutId);
|
||||||
|
@ -299,7 +318,7 @@ export default class App extends React.Component {
|
||||||
<SentryErrorBoundary dsn={this.props.sentryDsn}>
|
<SentryErrorBoundary dsn={this.props.sentryDsn}>
|
||||||
<AppContext.Provider value={this.getContextFromState()}>
|
<AppContext.Provider value={this.getContextFromState()}>
|
||||||
<CommentsBoxContainer done={done} />
|
<CommentsBoxContainer done={done} />
|
||||||
<AuthFrame adminUrl={this.props.adminUrl} onLoad={this.initSetup.bind(this)} initStatus={this.state.initStatus}/>
|
<AuthFrame adminUrl={this.props.adminUrl} onLoad={this.initAdminAuth.bind(this)}/>
|
||||||
<PopupModal />
|
<PopupModal />
|
||||||
</AppContext.Provider>
|
</AppContext.Provider>
|
||||||
</SentryErrorBoundary>
|
</SentryErrorBoundary>
|
||||||
|
|
|
@ -17,7 +17,7 @@ function addRootDiv() {
|
||||||
document.body.appendChild(elem);
|
document.body.appendChild(elem);
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.warn('Comment box location was not found: could not load comments box.');
|
console.warn('[Comments] Comment box location was not found: could not load comments box.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue