1
1
import { faSpinner } from '@fortawesome/free-solid-svg-icons' ;
2
2
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
3
+ import { API_BASE_URL } from 'app/../config/config' ;
3
4
import { NavBar , NavPage } from 'app/components/home/Navbar' ;
4
- // import { API_BASE_URL } from 'app/../config/config';
5
5
import PopUpMenu from 'app/components/PopUpMenu' ;
6
6
import { Routes } from 'app/routes' ;
7
7
import * as styles from 'app/styles/Authentication.module.css' ;
@@ -19,6 +19,8 @@ export enum OAUTH_ROUTES {
19
19
20
20
export class Login extends React . Component < LoginInterfaces . Props , LoginInterfaces . State > {
21
21
private loginRef = React . createRef < HTMLFormElement > ( ) ;
22
+ private authWindow : Window | null = null ;
23
+ private intervalID : null | ReturnType < typeof setTimeout > = null ;
22
24
23
25
constructor ( props : LoginInterfaces . Props ) {
24
26
super ( props ) ;
@@ -62,6 +64,9 @@ export class Login extends React.Component<LoginInterfaces.Props, LoginInterface
62
64
const { username, password } = this . state ;
63
65
const { errorMessage, isLoginLoading, isLoggedIn } = this . props ;
64
66
if ( isLoggedIn ) {
67
+ if ( this . authWindow != null ) this . authWindow . close ( ) ;
68
+ if ( this . intervalID != null ) clearInterval ( this . intervalID ) ;
69
+ this . props . setIsLoginLoading ( false ) ;
65
70
return < Redirect to = { Routes . ROOT } /> ;
66
71
}
67
72
@@ -83,50 +88,7 @@ export class Login extends React.Component<LoginInterfaces.Props, LoginInterface
83
88
account credentials to login.
84
89
</ div >
85
90
</ div >
86
- < div className = { classnames ( 'container px-0 justify-content-center' , styles . loginForm ) } >
87
- { /* {
88
- // TODO: Remove this on OAuth Integration.
89
- <Row
90
- onClick={(e) => {
91
- window.location.href = `https://code.pragyan.org/api/${OAUTH_ROUTES.GOOGLE}`;
92
- }}
93
- className={classnames(
94
- styles['google-btn'],
95
- 'border justify-content-center my-3',
96
- styles.oauth_btn,
97
- styles.no_margin,
98
- )}
99
- >
100
- <div className={classnames('col-auto my-2', styles.img_div)}>
101
- <img src="./assets/img/google.png" height="24" width="24" />
102
- </div>
103
- <p className="col-auto">Log in with Google</p>
104
- </Row>
105
- <Row
106
- onClick={(e) => {
107
- window.location.href = `${API_BASE_URL}${OAUTH_ROUTES.GITHUB}`;
108
- }}
109
- className={classnames(
110
- 'justify-content-center',
111
- styles['github-btn'],
112
- styles.oauth_btn,
113
- styles.no_margin,
114
- )}
115
- >
116
- <div className={classnames('col-auto my-2', styles.img_div)}>
117
- <img src="./assets/img/github.png" height="24" width="24" />
118
- </div>
119
- <p className="col-auto">Log in with Github</p>
120
- </Row>}
121
- <Row className={classnames(styles.no_margin)}>
122
- <div className={classnames(styles.separator)}>
123
- <div className={classnames(styles.wordWithLine)}>
124
- <span className={classnames(styles.text)}>or</span>
125
- </div>
126
- </div>
127
- </Row>
128
- */ }
129
- </ div >
91
+
130
92
< Row className = { classnames ( styles . no_margin ) } >
131
93
< div className = { classnames ( 'col-sm-10 offset-sm-1' , styles . form ) } >
132
94
< form
@@ -135,7 +97,32 @@ export class Login extends React.Component<LoginInterfaces.Props, LoginInterface
135
97
ref = { this . loginRef }
136
98
onSubmit = { this . handleLogin }
137
99
>
138
- < div className = "form-row" >
100
+ < Row
101
+ onClick = { ( e ) => {
102
+ this . authWindow = window . open ( `${ API_BASE_URL } ${ OAUTH_ROUTES . GOOGLE } ` ) ;
103
+ this . intervalID = setInterval ( this . props . getUserDetails , 500 ) ;
104
+ this . props . setIsLoginLoading ( true ) ;
105
+ } }
106
+ className = { classnames (
107
+ styles [ 'google-btn' ] ,
108
+ 'border justify-content-center my-3' ,
109
+ styles . oauth_btn ,
110
+ styles . no_margin ,
111
+ ) }
112
+ >
113
+ < div className = { classnames ( 'col-auto my-2' , styles . img_div ) } >
114
+ < img src = "./assets/img/google.png" height = "24" width = "24" />
115
+ </ div >
116
+ < p className = "col-auto" > Log in with Google</ p >
117
+ </ Row >
118
+ < Row className = { classnames ( styles . no_margin ) } >
119
+ < div className = { classnames ( styles . separator ) } >
120
+ < div className = { classnames ( styles . wordWithLine ) } >
121
+ < span className = { classnames ( styles . text ) } > or</ span >
122
+ </ div >
123
+ </ div >
124
+ </ Row >
125
+ < div className = "form-row mt-4" >
139
126
< div className = "col mb-4" >
140
127
< div className = { classnames ( styles [ 'login-label' ] ) } > Email </ div >
141
128
< div className = "input-group" >
0 commit comments