1
1
import React from "react" ;
2
2
import { Login } from "./actions" ;
3
3
import { connect } from "react-redux" ;
4
- import env from "utils/env"
4
+ import env from "utils/env" ;
5
5
6
6
import Heading from "react-bulma-components/lib/components/heading" ;
7
7
import Modal from "react-bulma-components/lib/components/modal" ;
8
8
9
-
10
9
class Connection extends React . Component {
11
10
constructor ( props ) {
12
11
super ( props ) ;
@@ -17,33 +16,29 @@ class Connection extends React.Component {
17
16
checkPopup ( ) {
18
17
const check = setInterval ( ( ) => {
19
18
const { popup } = this ;
20
- let url ;
21
-
22
- try {
23
- url = popup . location . href ;
24
- } catch ( error ) {
25
- url = "" ;
26
- }
27
19
28
- if ( ! popup || popup . closed || popup . closed === undefined ) {
20
+ if ( ( ! popup || popup . closed || popup . closed === undefined ) && ! this . props . logged ) {
29
21
clearInterval ( check ) ;
30
22
this . props . Login ( "RESET" ) ;
31
- } else if ( url . includes ( "access" ) ) {
32
- clearInterval ( check ) ;
23
+ }
24
+ } , 100 ) ;
33
25
34
- popup . close ( ) ;
26
+ window . addEventListener ( "message" , event => {
27
+ if ( event . data . origin === "lyrebird" ) {
28
+ this . popup . close ( ) ;
35
29
36
- console . log ( url ) ;
30
+ let url = event . data . url ;
37
31
38
32
let token = url . substring (
39
33
url . indexOf ( "#access_token=" ) + 14 ,
40
34
url . indexOf ( "&token_type" )
41
35
) ;
42
36
43
- console . log ( token ) ;
44
37
this . props . Login ( "SUCCESS" , token ) ;
38
+ } else {
39
+ return ;
45
40
}
46
- } , 100 ) ;
41
+ } ) ;
47
42
}
48
43
49
44
logIn ( ) {
@@ -53,7 +48,6 @@ class Connection extends React.Component {
53
48
const top = window . innerHeight / 2 - height / 2 ;
54
49
55
50
const url = "https://myvoice.lyrebird.ai/authorize" ;
56
- console . log ( env )
57
51
const clientId = env . clientId ;
58
52
const redirect = env . redirectUrl ;
59
53
const state = Math . floor ( Math . random ( ) * Math . floor ( 10000000 ) ) ;
@@ -91,7 +85,8 @@ class Connection extends React.Component {
91
85
92
86
const mapStateToProps = state => {
93
87
return {
94
- error : state . connection . error
88
+ error : state . connection . error ,
89
+ logged : state . connection . logged
95
90
} ;
96
91
} ;
97
92
0 commit comments