Skip to content

Commit

Permalink
Handle parentless popups
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-f committed Sep 14, 2017
1 parent 8ae06cd commit 41e445e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
4 changes: 3 additions & 1 deletion popup-app/components/IdpSelect.js
Expand Up @@ -78,7 +78,9 @@ class IdpSelect extends React.Component {
const { customIdp, enteringCustomIdp, error } = this.state
return (
<div>
<h1 className="center">Log in to {appName}</h1>
<h1 className="center">
Log in to <span className="app-name">{appName}</span>
</h1>
{error && <Error error={error} />}
<p className="copy-gentle center">Choose where you log in</p>
{enteringCustomIdp ? (
Expand Down
11 changes: 11 additions & 0 deletions popup-app/components/NoParent.js
@@ -0,0 +1,11 @@
import React from 'react'

const NoParent = ({ appName }) => (
<div>
This window was opened to log you in to{' '}
<span className="app-name">{appName}</span>, but that app is no longer open.
You can close this window.
</div>
)

export default NoParent
5 changes: 5 additions & 0 deletions popup-app/index.css
Expand Up @@ -61,3 +61,8 @@ h1 {
display: flex;
justify-content: flex-end;
}

.app-name {
text-decoration: underline;
font-weight: bold;
}
28 changes: 17 additions & 11 deletions popup-app/index.js
Expand Up @@ -7,6 +7,7 @@ import { getData, updateStorage } from '../src/storage'

import IdpCallback from './components/IdpCallback'
import IdpSelect from './components/IdpSelect'
import NoParent from './components/NoParent'

import './index.css'

Expand All @@ -24,24 +25,29 @@ const idps = [
]

findAppOrigin().then(appOrigin => {
ReactDOM.render(
window.location.hash ? (
const appName = process.env.APP_NAME

let element
if (!appOrigin) {
element = <NoParent appName={appName} />
} else if (window.location.hash) {
element = (
<IdpCallback
appOrigin={appOrigin}
afterLoggedIn={() => setTimeout(window.close, 750)}
/>
) : (
<IdpSelect
idps={idps}
appOrigin={appOrigin}
appName={process.env.APP_NAME}
/>
),
document.getElementById('app-container')
)
)
} else {
element = <IdpSelect idps={idps} appOrigin={appOrigin} appName={appName} />
}

ReactDOM.render(element, document.getElementById('app-container'))
})

async function findAppOrigin() {
if (!window.opener) {
return null
}
let appOrigin = await getStoredAppOrigin()
if (appOrigin) {
return appOrigin
Expand Down

0 comments on commit 41e445e

Please sign in to comment.