Skip to content
Snippets Groups Projects
Commit f6a0b74c authored by Sami Spets's avatar Sami Spets
Browse files

login working

parent 5d13cc32
Branches
Tags
No related merge requests found
Pipeline #14839 passed
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -14,7 +14,6 @@
"author": "Nicolas Pope",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.16.4",
"express-ws": "^4.0.0",
"jsonwebtoken": "^8.5.1",
......
body {
margin-left: auto;
margin-right: auto;
}
a {
-webkit-tap-highlight-color: transparent;
text-decoration: none;
}
.button {
display: inline-block;
max-width: 300px;
margin-top: 50px;
border: 0;
padding: 0 18px;
text-align: left;
width: 100%;
height: 37px;
border-radius: 4px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-moz-font-feature-settings: "liga" on;
color: rgba(0, 0, 0, 0.84) !important;
fill: rgba(0, 0, 0, 0.84) !important;
box-shadow: 0 1px 7px rgba(0, 0, 0, 0.05);
font: inherit;
outline: none;
}
.button .svgIcon {
vertical-align: middle;
fill: rgba(0, 0, 0, 0.54);
padding-right: 4px;
height: 37px;
display: inline-block;
}
.div {
vertical-align: center;
text-align: center
}
\ No newline at end of file
<!DOCTYPE html>
<html onload="checkIfLoggedIn()">
<head>
<title>FTL web-service</title>
</head>
<body onload="checkIfLoggedIn()">
<div id="container" style="padding-top: 150px; text-align: center">
<div id='Login'>
<h2>Welcome to Future Technology Lab</h2>
<h3>Please login!</h3>
<a className="button" onClick="handleLogin()">
<div>
<span class="svgIcon t-popup-svg">
<svg class="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 class="button-label">Sign in with Google</span>
</div>
</a>
</div>
</div>
</body>
<script src='./js/index.js'></script>
</html>
\ No newline at end of file
const checkIfLoggedIn = async () => {
const token = window.localStorage.getItem('token')
if(!token){
console.log("FAIL")
return ""
}else{
const response = await fetch('http://localhost:8080/auth/validation', {
method: 'POST',
headers: {'Authorization': token}
})
if(response.status === 200){
console.log("SUCCESS")
document.getElementById('container').innerHTML = "<p>Salainen sivu</p>"
}
}
}
const handleLogin = () => {
window.location.href="/google";
}
\ No newline at end of file
......@@ -6,12 +6,11 @@ const passport = require('passport');
const passportSetup = require('./passport/passport');
const jwt = require('jsonwebtoken');
const keys = require('./passport/keys')
const cors = require('cors');
// ---- INDEXES ----------------------------------------------------------------
app.use(passport.initialize());
app.use(express.static('build'))
app.use(cors())
app.use(express.static(__dirname + './../public'));
console.log(__dirname)
passport.serializeUser((user, done) => {
......@@ -143,6 +142,14 @@ app.get('/', (req, res) => {
res.end();
});
app.post('/auth/validation', (req, res) => {
const token = req.headers.authorization
const parts = token.split(" ")
const decoded = jwt.verify(parts[1], keys.jwt.secret)
console.log(decoded)
return res.status(200).json("Piipppiip")
})
// app.get('/login/google', (req, res) => {
// })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment