Skip to content

Commit dee1640

Browse files
committed
better OAuth
1 parent 5716fad commit dee1640

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

public/index.html

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
work correctly both with client-side routing and a non-root public URL.
2020
Learn how to configure a non-root public URL by running `npm run build`.
2121
-->
22+
<script>
23+
if(window.location.href.includes("access")) {
24+
window.opener.postMessage({url : window.location.href, origin: "lyrebird"}, '*');
25+
}
26+
</script>
2227
<title>React App</title>
2328
</head>
2429
<body>

src/Connection/index.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from "react";
22
import { Login } from "./actions";
33
import { connect } from "react-redux";
4-
import env from "utils/env"
4+
import env from "utils/env";
55

66
import Heading from "react-bulma-components/lib/components/heading";
77
import Modal from "react-bulma-components/lib/components/modal";
88

9-
109
class Connection extends React.Component {
1110
constructor(props) {
1211
super(props);
@@ -17,33 +16,29 @@ class Connection extends React.Component {
1716
checkPopup() {
1817
const check = setInterval(() => {
1918
const { popup } = this;
20-
let url;
21-
22-
try {
23-
url = popup.location.href;
24-
} catch (error) {
25-
url = "";
26-
}
2719

28-
if (!popup || popup.closed || popup.closed === undefined) {
20+
if ((!popup || popup.closed || popup.closed === undefined) && !this.props.logged) {
2921
clearInterval(check);
3022
this.props.Login("RESET");
31-
} else if (url.includes("access")) {
32-
clearInterval(check);
23+
}
24+
}, 100);
3325

34-
popup.close();
26+
window.addEventListener("message", event => {
27+
if (event.data.origin === "lyrebird") {
28+
this.popup.close();
3529

36-
console.log(url);
30+
let url = event.data.url;
3731

3832
let token = url.substring(
3933
url.indexOf("#access_token=") + 14,
4034
url.indexOf("&token_type")
4135
);
4236

43-
console.log(token);
4437
this.props.Login("SUCCESS", token);
38+
} else {
39+
return;
4540
}
46-
}, 100);
41+
});
4742
}
4843

4944
logIn() {
@@ -53,7 +48,6 @@ class Connection extends React.Component {
5348
const top = window.innerHeight / 2 - height / 2;
5449

5550
const url = "https://myvoice.lyrebird.ai/authorize";
56-
console.log(env)
5751
const clientId = env.clientId;
5852
const redirect = env.redirectUrl;
5953
const state = Math.floor(Math.random() * Math.floor(10000000));
@@ -91,7 +85,8 @@ class Connection extends React.Component {
9185

9286
const mapStateToProps = state => {
9387
return {
94-
error: state.connection.error
88+
error: state.connection.error,
89+
logged: state.connection.logged
9590
};
9691
};
9792

0 commit comments

Comments
 (0)