-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e33bc3d
commit 7f5042e
Showing
9 changed files
with
320 additions
and
35 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
misses-ed-app/misses-ed-app/ClientApp/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,83 @@ | ||
import React, { Component } from 'react'; | ||
import React, { Component, useState, useEffect } from 'react'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import AppRoutes from './AppRoutes'; | ||
import { Layout } from './components/Layout'; | ||
import Layout from './components/Layout'; | ||
import './custom.css'; | ||
import './login.css'; | ||
import { Login } from './components/Login'; | ||
import { GoogleLogin, googleLogout, useGoogleLogin } from '@react-oauth/google'; | ||
import axios from 'axios'; | ||
|
||
export default class App extends Component { | ||
static displayName = App.name; | ||
function App() { | ||
const [ authenticated, setAuthenticated] = useState(false); | ||
const [ user, setUser ] = useState([]); | ||
const [ profile, setProfile ] = useState([]); | ||
|
||
render() { | ||
return ( | ||
<Layout> | ||
<Routes> | ||
{AppRoutes.map((route, index) => { | ||
const { element, ...rest } = route; | ||
return <Route key={index} {...rest} element={element} />; | ||
})} | ||
</Routes> | ||
</Layout> | ||
const login = useGoogleLogin({ | ||
onSuccess: (codeResponse) => setUser(codeResponse), | ||
onError: (error) => console.log('Login Failed:', error) | ||
}); | ||
|
||
useEffect( | ||
() => { | ||
console.log(user); | ||
if (user.access_token) { | ||
axios | ||
.get(`https://www.googleapis.com/oauth2/v3/userinfo?access_token=${user.access_token}`, { | ||
headers: { | ||
Authorization: `Bearer ${user.access_token}`, | ||
Accept: 'application/json' | ||
} | ||
}) | ||
.then((res) => { | ||
setProfile(res.data); | ||
console.log(res.data); | ||
setAuthenticated(true); | ||
}) | ||
.catch((err) => console.log(err)); | ||
} | ||
}, | ||
[ user ] | ||
); | ||
|
||
// log out function to log the user out of google and set the profile array to null | ||
const logOut = () => { | ||
googleLogout(); | ||
setProfile(null); | ||
setAuthenticated(false); | ||
}; | ||
|
||
|
||
if(authenticated) { | ||
return ( | ||
<Layout logOut={logOut}> | ||
<Routes> | ||
{AppRoutes.map((route, index) => { | ||
const { element, ...rest } = route; | ||
return <Route key={index} {...rest} element={element} />; | ||
})} | ||
</Routes> | ||
</Layout> | ||
); | ||
} else { | ||
return( | ||
<div className='floating-wrapper'> | ||
<h1>Misses ED</h1> | ||
<h3 className='mb-5'>SENG 350 - Group 6</h3> | ||
<h6 className='mb-4'>Sign in to continue with all features</h6> | ||
<button className='mb-4 button nice-button' onClick={() => login()}> | ||
<div className='inset nice-button-active lead'> | ||
Sign in with Google | ||
</div> | ||
</button> | ||
<h6 className='mb-4 text-center'>Or</h6> | ||
{/* FYI this will be changed in the future to set a flag indicating whether user is a guest */} | ||
<button className='button lead' onClick={() => setAuthenticated(true)}>Continue as Guest</button> | ||
<p className='bottom'>©2023</p> | ||
</div> | ||
); | ||
} | ||
|
||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
misses-ed-app/misses-ed-app/ClientApp/src/components/Login.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React, { Component } from 'react'; | ||
|
||
export class Login extends Component { | ||
static displayName = Login.name; | ||
|
||
render() { | ||
return ( | ||
<a href="/.auth/login/google">Log in with Google</a> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ a.navbar-brand { | |
|
||
a:hover { | ||
background-color: #efefef; | ||
cursor: pointer; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.