Skip to content

Commit

Permalink
[default-login] Don't add projectId param when global login (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin authored and bjoerge committed Oct 19, 2017
1 parent fe152cb commit a756339
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
35 changes: 22 additions & 13 deletions packages/@sanity/default-login/src/LoginDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
import React from 'react'
import PropTypes from 'prop-types'
import authenticationFetcher from 'part:@sanity/base/authentication-fetcher'
import client from 'part:@sanity/base/client'
import cancelWrap from './cancelWrap'
import styles from './styles/LoginDialog.css'
import SanityStudioLogo from 'part:@sanity/base/sanity-studio-logo'
import config from 'config:sanity'
import BrandLogo from 'part:@sanity/base/brand-logo?'

Expand All @@ -31,11 +29,17 @@ const GoogleLogo = () => (
export default class LoginDialog extends React.Component {
static propTypes = {
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
sanityLogo: PropTypes.node.isRequired,
showSanityLogo: PropTypes.bool.isRequired
description: PropTypes.string,
sanityLogo: PropTypes.node,
projectId: PropTypes.string
};

static defaultProps = {
description: null,
sanityLogo: null,
projectId: null
}

state = {
providers: [],
error: null
Expand All @@ -54,18 +58,23 @@ export default class LoginDialog extends React.Component {

handleLoginButtonClicked(provider, evnt) {
evnt.preventDefault()
const projectId = client.config().projectId
const {projectId} = this.props
const currentUrl = encodeURIComponent(window.location.toString())
window.location = `${provider.url}?origin=${currentUrl}&projectId=${projectId}`
const params = [
`origin=${currentUrl}`,
projectId && `projectId=${projectId}`
].filter(Boolean)
window.location = `${provider.url}?${params.join('&')}`
}

renderLoginScreen() {
const {title, description, sanityLogo} = this.props
return (
<div className={styles.root}>

{ this.props.showSanityLogo && (
<div className={styles.sanityStudioLogo}>
{ this.props.sanityLogo ? this.props.sanityLogo : <SanityStudioLogo />}
{ sanityLogo && (
<div className={styles.sanityLogo}>
{sanityLogo}
</div>
)}

Expand All @@ -78,10 +87,10 @@ export default class LoginDialog extends React.Component {

<div className={styles.inner}>
<h2 className={styles.title}>
{this.props.title}
{title}
</h2>
{ this.props.description && (
<div className={styles.description}>{this.props.description}</div>
{ description && (
<div className={styles.description}>{description}</div>
)}
<ul className={styles.providers}>
{this.state.providers.map(provider => {
Expand Down
18 changes: 11 additions & 7 deletions packages/@sanity/default-login/src/LoginWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@ import PropTypes from 'prop-types'
import React from 'react'
import client from 'part:@sanity/base/client'
import userStore from 'part:@sanity/base/user'

import CookieTest from './CookieTest'
import LoginDialog from 'part:@sanity/base/login-dialog'
import UnauthorizedUser from './UnauthorizedUser'
import ErrorDialog from './ErrorDialog'
import SanityStudioLogo from 'part:@sanity/base/sanity-studio-logo'
import Spinner from 'part:@sanity/components/loading/spinner'
import CookieTest from './CookieTest'
import UnauthorizedUser from './UnauthorizedUser'


const isProjectLogin = client.config().useProjectHostname
const projectId = (isProjectLogin && client.config().projectId)
? client.config().projectId : null

export default class LoginWrapper extends React.PureComponent {

static propTypes = {
children: PropTypes.node.isRequired,
title: PropTypes.string,
description: PropTypes.string,
sanityLogo: PropTypes.node,
showSanityLogo: PropTypes.bool
sanityLogo: PropTypes.node
}

static defaultProps = {
title: 'Choose login provider',
description: null,
sanityLogo: null,
showSanityLogo: true
sanityLogo: <SanityStudioLogo />,
};

state = {isLoading: true, user: null, error: null}
Expand Down Expand Up @@ -65,12 +68,13 @@ export default class LoginWrapper extends React.PureComponent {
description={this.props.description}
sanityLogo={this.props.sanityLogo}
showSanityLogo={this.props.showSanityLogo}
projectId={projectId}
/>
</CookieTest>
)
}

if (isProjectLogin && !user.role) {
if (projectId && !user.role) {
return <UnauthorizedUser user={user} />
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/default-login/src/styles/LoginDialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
color: var(--text-color);
}

.sanityStudioLogo {
.sanityLogo {
width: 8rem;
margin: 4rem auto;

Expand Down

0 comments on commit a756339

Please sign in to comment.