Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes the login loading issue #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions frontend/src/Pages/Auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { useMutation } from '@apollo/client'

import gql from 'graphql-tag.macro'

// This import loads the firebase namespace along with all its type information.
import firebase from 'firebase/app'
import 'firebase/auth'

import { Navigate } from 'react-router-dom'
import { SmallLoadingPage } from './../../components/LoadingComponents'
const AUTHENTICATE_USER = gql`
Expand All @@ -29,6 +33,7 @@ const lstorage = localStorage
function Auth () {
const idToken = lstorage.getItem('token')


// Run query against backend to authenticate user
const [
authenticateUser,
Expand Down
13 changes: 3 additions & 10 deletions frontend/src/Pages/Login/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logo from './HedwigLogoFinal_02.svg'
import { useState } from 'react'
import { MainDiv, ElemDiv, Logo, Title, LoginButton } from './Login.styles'

// import './Transitions.css';
Expand All @@ -15,24 +16,16 @@ function Login () {
/* Lets user sign in in a pop-up tab, get the user's info then generates a token. */
const signInSAML = () => {
firebase.auth().signInWithRedirect(provider)
navigate('/loadingAuth')
}

firebase
.auth()
.getRedirectResult()
.then(result => result.user.getIdTokenResult(true))
.then(idTokenResult => {
localStorage.setItem('token', idTokenResult.token)
navigate('/auth')
})
.catch(error => console.log(error))

return (
<MainDiv>
<ElemDiv>
<Logo src={logo} />
<Title>hedwig</Title>
<LoginButton onClick={signInSAML}>Login with NetID</LoginButton>
<LoginButton onClick={signInSAML}>Login with NetID</LoginButton>
</ElemDiv>
</MainDiv>
)
Expand Down
26 changes: 26 additions & 0 deletions frontend/src/Pages/Login/loadingAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This import loads the firebase namespace along with all its type information.
import firebase from 'firebase/app'
import 'firebase/auth'
// import './Transitions.css';
import { useNavigate } from 'react-router-dom'
import { LoadingPage } from '../../components/LoadingComponents'

function LoadingAuth() {
const navigate = useNavigate()

firebase
.auth()
.getRedirectResult()
.then(result => result.user.getIdTokenResult(true))
.then(idTokenResult => {
localStorage.setItem('token', idTokenResult.token)
navigate('/auth')
})
.catch(error => console.log(error))

return (
<LoadingPage />
)
}

export default LoadingAuth;
6 changes: 6 additions & 0 deletions frontend/src/components/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { SmallLoadingPage } from './LoadingComponents'
import Launch from './../Pages/User/Launch'
import Onboard from './../Pages/Onboard/Onboard'
import ReturnOnboard from './../Pages/Onboard/ReturnOnboard'
import LoadingAuth from './../Pages/Login/loadingAuth'

/**
* Requests to verify the user's token on the backend
*/
Expand Down Expand Up @@ -175,6 +177,10 @@ export const RoutesComponent = () => {
path: '/login',
element: <Login />
},
{
path: '/loadingAuth',
element: <PrivateRoute element={<LoadingAuth />} />
},
{
path: '/auth',
element: <Auth />
Expand Down