-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
index.js
72 lines (66 loc) · 1.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React from 'react';
import Centered from '@codesandbox/common/lib/components/flex/Centered';
import {
protocolAndHost,
signInUrl,
newSandboxUrl,
} from '@codesandbox/common/lib/utils/url-generator';
import { Title } from 'app/components/Title';
// This route is supposed to be opened in a new window, after signing in with
// Github. It should return a postMessage to the parent
// eslint-disable-line-import/no-default-export
export default class SignIn extends React.PureComponent {
constructor(props) {
super(props);
if (props.match.params.jwt) {
if (window.opener) {
this.state = {
jwt: props.match.params.jwt,
};
if (window.opener.location.origin === window.location.origin) {
window.opener.postMessage(
{
type: 'signin',
data: {
jwt: props.match.params.jwt,
},
},
protocolAndHost()
);
}
return;
}
this.state = {
redirect: '/',
};
return;
}
this.state = {
error: 'no message received',
};
}
getMessage = () => {
if (this.state.redirect) {
document.location.href = newSandboxUrl();
return 'Redirecting to sandbox page';
}
if (this.state.error) {
return `Something went wrong while signing in: ${this.state.error}`;
}
if (this.state.jwt) return 'Signing in...';
if (this.state.jwt == null) {
setTimeout(() => {
document.location.href = signInUrl();
}, 2000);
return 'Redirecting to sign in page...';
}
return 'Hey';
};
render() {
return (
<Centered horizontal vertical>
<Title>{this.getMessage()}</Title>
</Centered>
);
}
}