Skip to content

Commit

Permalink
[default-login] Fix invalid notice of no providers configured message…
Browse files Browse the repository at this point in the history
… + fix deprecated React lifecycle methods (#1021)
  • Loading branch information
skogsmaskin authored and bjoerge committed Oct 16, 2018
1 parent 63c89eb commit 6a17f98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
44 changes: 26 additions & 18 deletions packages/@sanity/default-login/src/LoginDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,31 @@ export default class LoginDialog extends React.Component {

state = {
providers: [],
isLoaded: false,
shouldRedirect: false,
error: null
}

componentDidMount() {
this.getProviders = cancelWrap(authenticationFetcher.getProviders())
this.getProviders.promise
.then(providers => this.setState({providers: providers}))
.then(providers =>
this.setState({
providers: providers,
isLoaded: true,
shouldRedirect: providers.length === 1 && pluginConfig.providers.redirectOnSingle
})
)
.catch(err => this.setState({error: err}))
}

componentWillUnmount() {
this.getProviders.cancel()
}

componentWillUpdate(_, nextState) {
const {providers} = nextState
if (
providers.length === 1 &&
(pluginConfig.providers && pluginConfig.providers.redirectOnSingle)
) {
componentDidUpdate() {
const {providers, isLoaded, shouldRedirect} = this.state
if (isLoaded && shouldRedirect) {
this.redirectToProvider(providers[0])
}
}
Expand Down Expand Up @@ -84,7 +89,7 @@ export default class LoginDialog extends React.Component {
}

render() {
const {error, providers} = this.state
const {error, providers, isLoaded, shouldRedirect} = this.state
const {title, description, SanityLogo} = this.props

if (error) {
Expand All @@ -108,18 +113,21 @@ export default class LoginDialog extends React.Component {
)
}

if (providers.length < 1) {
if (isLoaded && providers.length === 0) {
return <div>No providers configured</div>
}

return (
<LoginDialogContent
title={title}
description={description}
providers={providers}
SanityLogo={SanityLogo}
onLoginButtonClick={this.handleLoginButtonClicked}
/>
)
if (isLoaded && !shouldRedirect) {
return (
<LoginDialogContent
title={title}
description={description}
providers={providers}
SanityLogo={SanityLogo}
onLoginButtonClick={this.handleLoginButtonClicked}
/>
)
}
return null
}
}
4 changes: 3 additions & 1 deletion packages/@sanity/default-login/src/LoginWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export default class LoginWrapper extends React.PureComponent {

state = {isLoading: true, user: null, error: null}

componentWillMount() {
userSubscription = null

componentDidMount() {
const sid = getSid()

if (sid) {
Expand Down

0 comments on commit 6a17f98

Please sign in to comment.