From 0f24d356ac4189c565c9e73556660815ac7e0c19 Mon Sep 17 00:00:00 2001 From: Sami Spets <savasp@utu.fi> Date: Mon, 23 Sep 2019 22:26:45 +0300 Subject: [PATCH] minor changes --- web-service/client/src/App.js | 35 +++++++++++---------------------- web-service/client/src/Login.js | 27 +++++++++++++++++++++++++ web-service/server/src/index.js | 3 ++- 3 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 web-service/client/src/Login.js diff --git a/web-service/client/src/App.js b/web-service/client/src/App.js index a758c4afc..377d85c4f 100644 --- a/web-service/client/src/App.js +++ b/web-service/client/src/App.js @@ -2,10 +2,20 @@ import React, { useState } from 'react'; import './App.css' //import {Route, BrowserRouter, Link} from 'react-router-domm import Streams from './Streams' +import Login from './Login' const App = () => { const [user, setUser] = useState(null); + const [streams, setStreams] = useState(null); + + /** + * TODO: create a list available of streams using useEffect. + * Each index is an object (stream) that has a name and a picture. + * When making the request for the objects the same request + * authenticates the users JWT + * + */ const handleLogin = () => { //BEFORE BUILD CHANGE THE URL TO /google @@ -19,34 +29,11 @@ const App = () => { if(window.localStorage.getItem('token')){ return ( - /* - This should redirect the router path to point at /streams - So instead of the div down below it would render - <Streams /> - */ <Streams clearCookies={clearCookies}/> ) } return ( - <div style={{'padding-top': '150px', 'text-align': 'center'}}> - <h2>Welcome to Future Technology Lab</h2> - <h3>Please login!</h3> - <a className="button" onClick={handleLogin}> - <div> - <span className="svgIcon t-popup-svg"> - <svg className="svgIcon-use" width="25" height="37" viewBox="0 0 25 25"> - <g fill="none" fill-rule="evenodd"> - <path d="M20.66 12.693c0-.603-.054-1.182-.155-1.738H12.5v3.287h4.575a3.91 3.91 0 0 1-1.697 2.566v2.133h2.747c1.608-1.48 2.535-3.65 2.535-6.24z" fill="#4285F4"/> - <path d="M12.5 21c2.295 0 4.22-.76 5.625-2.06l-2.747-2.132c-.76.51-1.734.81-2.878.81-2.214 0-4.088-1.494-4.756-3.503h-2.84v2.202A8.498 8.498 0 0 0 12.5 21z" fill="#34A853"/> - <path d="M7.744 14.115c-.17-.51-.267-1.055-.267-1.615s.097-1.105.267-1.615V8.683h-2.84A8.488 8.488 0 0 0 4 12.5c0 1.372.328 2.67.904 3.817l2.84-2.202z" fill="#FBBC05"/> - <path d="M12.5 7.38c1.248 0 2.368.43 3.25 1.272l2.437-2.438C16.715 4.842 14.79 4 12.5 4a8.497 8.497 0 0 0-7.596 4.683l2.84 2.202c.668-2.01 2.542-3.504 4.756-3.504z" fill="#EA4335"/> - </g> - </svg> - </span> - <span className="button-label">Sign in with Google</span> - </div> - </a> - </div> + <Login handleLogin={handleLogin} /> ) } diff --git a/web-service/client/src/Login.js b/web-service/client/src/Login.js new file mode 100644 index 000000000..67fc5fd26 --- /dev/null +++ b/web-service/client/src/Login.js @@ -0,0 +1,27 @@ +import React from 'react'; + +const Login = ({handleLogin}) => { + return( + <div style={{'padding-top': '150px', 'text-align': 'center'}}> + <h2>Welcome to Future Technology Lab</h2> + <h3>Please login!</h3> + <a className="button" onClick={handleLogin}> + <div> + <span className="svgIcon t-popup-svg"> + <svg className="svgIcon-use" width="25" height="37" viewBox="0 0 25 25"> + <g fill="none" fill-rule="evenodd"> + <path d="M20.66 12.693c0-.603-.054-1.182-.155-1.738H12.5v3.287h4.575a3.91 3.91 0 0 1-1.697 2.566v2.133h2.747c1.608-1.48 2.535-3.65 2.535-6.24z" fill="#4285F4"/> + <path d="M12.5 21c2.295 0 4.22-.76 5.625-2.06l-2.747-2.132c-.76.51-1.734.81-2.878.81-2.214 0-4.088-1.494-4.756-3.503h-2.84v2.202A8.498 8.498 0 0 0 12.5 21z" fill="#34A853"/> + <path d="M7.744 14.115c-.17-.51-.267-1.055-.267-1.615s.097-1.105.267-1.615V8.683h-2.84A8.488 8.488 0 0 0 4 12.5c0 1.372.328 2.67.904 3.817l2.84-2.202z" fill="#FBBC05"/> + <path d="M12.5 7.38c1.248 0 2.368.43 3.25 1.272l2.437-2.438C16.715 4.842 14.79 4 12.5 4a8.497 8.497 0 0 0-7.596 4.683l2.84 2.202c.668-2.01 2.542-3.504 4.756-3.504z" fill="#EA4335"/> + </g> + </svg> + </span> + <span className="button-label">Sign in with Google</span> + </div> + </a> + </div> + ) +} + +export default Login; \ No newline at end of file diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index 16c8ba036..c4062d542 100644 --- a/web-service/server/src/index.js +++ b/web-service/server/src/index.js @@ -5,6 +5,7 @@ const Peer = require('./peer.js'); const passport = require('passport'); const passportSetup = require('./passport/passport'); const jwt = require('jsonwebtoken'); +const keys = require('./passport/keys') // ---- INDEXES ---------------------------------------------------------------- app.use(passport.initialize()); @@ -165,7 +166,7 @@ app.get('/google', passport.authenticate('google', { */ app.get('/auth/google/redirect', passport.authenticate('google'), (req, res) => { console.log(req.user) - const token = jwt.sign(req.user.id, 'Somesecretkey14madlh£$'); + const token = jwt.sign(req.user.id, keys.jwt.secret); const htmlWithEmbeddedJWT = ` <html> <body><h3> You will be automatically redirected to next page.<h3><body> -- GitLab