@@ -2,7 +2,7 @@ import React from 'react'
22
33import auth from '../../src'
44import { Client } from '../../src/ipc'
5- import { ipcStorage } from '../../src/storage'
5+ import { ipcStorage , getData } from '../../src/storage'
66
77import './IdpSelect.css'
88
@@ -15,8 +15,7 @@ class IdpSelect extends React.Component {
1515
1616 toggleEnteringCustomIdp = ( ) =>
1717 this . setState ( currentState => ( {
18- enteringCustomIdp : ! currentState . enteringCustomIdp ,
19- customIdp : { url : '' }
18+ enteringCustomIdp : ! currentState . enteringCustomIdp
2019 } ) )
2120
2221 handleChangeIdp = event => {
@@ -35,7 +34,6 @@ class IdpSelect extends React.Component {
3534 }
3635
3736 handleSelectIdp = idp => async event => {
38- const { appOrigin } = this . props
3937 event . preventDefault ( )
4038 if ( ! window . opener ) {
4139 console . warn ( 'No parent window' )
@@ -46,14 +44,28 @@ class IdpSelect extends React.Component {
4644 } )
4745 return
4846 }
49- const client = new Client ( window . opener , appOrigin )
5047 const loginOptions = {
51- ...( await client . request ( 'getLoginOptions' ) ) ,
52- storage : ipcStorage ( client )
48+ ...( await this . getClient ( ) . request ( 'getLoginOptions' ) ) ,
49+ storage : this . getStorage ( )
5350 }
5451 await auth . login ( idp . url , loginOptions )
5552 }
5653
54+ getClient ( ) {
55+ return new Client ( window . opener , this . props . appOrigin )
56+ }
57+
58+ getStorage ( ) {
59+ return ipcStorage ( this . getClient ( ) )
60+ }
61+
62+ async componentDidMount ( ) {
63+ const { rpConfig } = await getData ( this . getStorage ( ) )
64+ if ( rpConfig ) {
65+ this . setState ( { customIdp : { url : rpConfig . provider . url } } )
66+ }
67+ }
68+
5769 componentDidUpdate ( ) {
5870 if ( this . idpInput ) {
5971 this . idpInput . focus ( )
0 commit comments