Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@apollo/client": "^3.2.2",
"@lara/components": "^1.0.0",
"@react-oauth/google": "^0.5.1",
"@rebass/grid": "^6.1.0",
"apollo-link-token-refresh": "^0.4.0",
"date-fns": "^2.16.1",
Expand All @@ -26,7 +27,6 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-focus-lock": "^2.9.0",
"react-google-login": "^5.1.21",
"react-hook-form": "^7.28.1",
"react-localization": "^1.0.15",
"react-router": "^5.2.0",
Expand Down
9 changes: 6 additions & 3 deletions packages/frontend/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { Router, Switch } from 'react-router-dom'
import { GoogleOAuthProvider } from '@react-oauth/google'

import ApolloProvider from './apollo-provider'
import AppHistory from './app-history'
Expand All @@ -17,9 +18,11 @@ export const App: React.FunctionComponent = () => {

return (
<AuthenticationContext.Provider value={{ authenticated, setAuthenticated }}>
<ApolloProvider>
<InnerApp />
</ApolloProvider>
<GoogleOAuthProvider clientId={ENVIRONMENT.googleClientID}>
<ApolloProvider>
<InnerApp />
</ApolloProvider>
</GoogleOAuthProvider>
</AuthenticationContext.Provider>
)
}
Expand Down
26 changes: 11 additions & 15 deletions packages/frontend/src/pages/login-page.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import React, { useState } from 'react'
import { GoogleLogin, GoogleLoginResponse, GoogleLoginResponseOffline } from 'react-google-login'
import { TokenResponse, useGoogleLogin } from '@react-oauth/google'

import { Container, Paragraph, Spacer, StyledLogo } from '@lara/components'

import AppHistory from '../app-history'
import { PrimaryButton } from '../components/button'
import { useLoginPageLoginMutation } from '../graphql'
import { useAuthentication } from '../hooks/use-authentication'
import { Template } from '../templates/template'
import { SplashPage } from './splash-page'
import { PrimaryButton } from '../components/button'

const LoginPage: React.FunctionComponent = () => {
const { login } = useAuthentication()
const [mutate] = useLoginPageLoginMutation()

const [authLoading, setAuthLoading] = useState(false)

const onLoginSuccess = (googleResponse: GoogleLoginResponse | GoogleLoginResponseOffline) => {
const googleLogin = useGoogleLogin({
onSuccess: (tokenResponse: TokenResponse) => onLoginSuccess(tokenResponse),
onError: () => onLoginFailure,
})

const onLoginSuccess = (tokenResponse: TokenResponse) => {
setAuthLoading(true)

if (!('getAuthResponse' in googleResponse)) {
if (!tokenResponse) {
return
}

const accessToken = googleResponse.getAuthResponse().access_token
const accessToken = tokenResponse.access_token

mutate({ variables: { token: accessToken } }).then((response) => {
const { data } = response
Expand Down Expand Up @@ -57,16 +62,7 @@ const LoginPage: React.FunctionComponent = () => {
</Paragraph>
</Spacer>
<Paragraph center noMargin>
<GoogleLogin
render={({ onClick, disabled }) => (
<PrimaryButton onClick={onClick} disabled={disabled}>
sign in with Google
</PrimaryButton>
)}
clientId={ENVIRONMENT.googleClientID}
onSuccess={onLoginSuccess}
onFailure={onLoginFailure}
/>
<PrimaryButton onClick={() => googleLogin()}>sign in with Google</PrimaryButton>
</Paragraph>
</Container>
</Template>
Expand Down
11 changes: 8 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3881,6 +3881,11 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==

"@react-oauth/google@^0.5.1":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@react-oauth/google/-/google-0.5.1.tgz#fc5cf33bff5d59583c5b0ed387431350216dd907"
integrity sha512-XCMMke24klAHIVnrZAMibodyjSUsxBOJ+vO5yvRptWC2Vnq02uLUnydjtIdCzCUIAxbvbFbQWZxG0xF0Y8GtHA==

"@rebass/grid@^6.1.0":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@rebass/grid/-/grid-6.1.0.tgz#17827e13d9b461d86e3e5c6b47393b5aea857370"
Expand Down Expand Up @@ -4558,9 +4563,9 @@
"@types/react" "*"

"@types/react@*", "@types/react@^17", "@types/react@^17.0.4", "@types/react@^17.0.9":
version "17.0.50"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.50.tgz#39abb4f7098f546cfcd6b51207c90c4295ee81fc"
integrity sha512-ZCBHzpDb5skMnc1zFXAXnL3l1FAdi+xZvwxK+PkglMmBrwjpp9nKaWuEvrGnSifCJmBFGxZOOFuwC6KH/s0NuA==
version "17.0.52"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.52.tgz#10d8b907b5c563ac014a541f289ae8eaa9bf2e9b"
integrity sha512-vwk8QqVODi0VaZZpDXQCmEmiOuyjEFPY7Ttaw5vjM112LOq37yz1CDJGrRJwA1fYEq4Iitd5rnjd1yWAc/bT+A==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
Expand Down