Skip to content

Commit f318185

Browse files
committed
Fix google login in error page
1 parent 501bcd0 commit f318185

File tree

2 files changed

+20
-82
lines changed

2 files changed

+20
-82
lines changed

src/cloud/components/SignInForm/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const SignInForm = ({
5959
disabled={disabled || preventAction}
6060
setDisabled={setDisabled}
6161
query={loginQuery}
62-
setError={setError}
6362
style={{ margin: '0 auto 10px', display: 'block' }}
6463
/>
6564
<GithubLoginButton

src/cloud/components/buttons/login/GoogleLoginButton.tsx

Lines changed: 20 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import React, { useState, useCallback } from 'react'
1+
import React, { useState } from 'react'
22
import cc from 'classcat'
3-
import GoogleLogin from 'react-google-login'
4-
import { postGoogleLoginCallback } from '../../../api/auth/google'
5-
import { useRouter } from '../../../lib/router'
3+
import { stringify } from 'querystring'
64
import { mdiGoogle } from '@mdi/js'
5+
import { boostHubBaseUrl } from '../../../lib/consts'
76
import styled from '../../../../design/lib/styled'
87
import Icon from '../../../../design/components/atoms/Icon'
98

@@ -15,7 +14,6 @@ interface GoogleLoginButtonProps {
1514
query?: any
1615
disabled: boolean
1716
setDisabled: (val: boolean) => void
18-
setError: (err: unknown) => void
1917
}
2018

2119
const GoogleLoginButton = ({
@@ -24,91 +22,32 @@ const GoogleLoginButton = ({
2422
query,
2523
disabled,
2624
setDisabled,
27-
setError,
2825
}: GoogleLoginButtonProps) => {
2926
const [sending, setSending] = useState<boolean>(false)
30-
const [googleAuthIsInitialized, setGoogleAuthIsInitialized] = useState<
31-
boolean
32-
>(true)
33-
const { push } = useRouter()
34-
35-
const responseGoogle = useCallback(
36-
async (response: any) => {
37-
setSending(true)
38-
setDisabled(true)
39-
setError(undefined)
40-
try {
41-
const data = await postGoogleLoginCallback({
42-
...query,
43-
tokenId: response.tokenId,
44-
accessToken: response.accessToken,
45-
googleId: response.googleId,
46-
scope: response.tokenObj.scope,
47-
})
48-
push(data.redirectTo)
49-
} catch (error) {
50-
setError(error)
51-
setDisabled(false)
52-
setSending(false)
53-
}
54-
},
55-
[query, setError, push, setDisabled]
56-
)
57-
58-
const errorHandler = (response: any) => {
59-
console.log(response.error)
60-
if (response.error === 'popup_closed_by_user') {
61-
return
62-
}
63-
64-
if (response.error === 'idpiframe_initialization_failed') {
65-
setGoogleAuthIsInitialized(false)
66-
setError(
67-
`Third-party cookies and site data need to be enabled for Google Auth to work properly. Please adjust your browser settings.`
68-
)
69-
return
70-
}
71-
72-
setError(response.error)
73-
}
74-
75-
if (process.env.GOOGLE_CLIENT_ID == null) {
76-
return null
77-
}
27+
const loginHref = `${boostHubBaseUrl}/api/oauth/google${
28+
query != null ? `?${stringify(query)}` : ''
29+
}`
7830

7931
return (
80-
<GoogleLogin
81-
clientId={process.env.GOOGLE_CLIENT_ID}
82-
render={(renderProps) => (
83-
<StyledGoogleButton
84-
onClick={renderProps.onClick}
85-
disabled={
86-
renderProps.disabled ||
87-
sending ||
88-
disabled ||
89-
!googleAuthIsInitialized
90-
}
91-
style={style}
92-
className={cc(['login-google-btn g-signin2', className])}
93-
>
94-
<Icon path={mdiGoogle} />
95-
{sending ? (
96-
<span>Signing in...</span>
97-
) : (
98-
<span>Continue with Google</span>
99-
)}
100-
</StyledGoogleButton>
101-
)}
102-
onSuccess={responseGoogle}
103-
onFailure={errorHandler}
104-
cookiePolicy={'single_host_origin'}
105-
/>
32+
<StyledGoogleButton
33+
onClick={() => {
34+
setDisabled(true)
35+
setSending(true)
36+
}}
37+
href={loginHref}
38+
disabled={disabled}
39+
style={style}
40+
className={cc(['login-google-btn', disabled && 'disabled', className])}
41+
>
42+
<Icon path={mdiGoogle} />
43+
{sending ? <span>Signing in...</span> : <span>Continue with Google</span>}
44+
</StyledGoogleButton>
10645
)
10746
}
10847

10948
export default GoogleLoginButton
11049

111-
const StyledGoogleButton = styled.button`
50+
const StyledGoogleButton = styled.a`
11251
text-decoration: none;
11352
width: 100%;
11453
height: 40px;

0 commit comments

Comments
 (0)