-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (27 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
export const renderSite = function() {
const $root = $('#root');
let jwt = localStorage.getItem('jwt');
if (jwt && jwt != 'undefined') { // means user is logged in
$('#logButton').replaceWith(`<a class="link is-dark" id="logButton" href="index.html"><button class="button is-success navbutton">Logout</button></a>`);
$root.on('click', '#logButton', handleLogoutPress);
}
$root.on('click', '#tripsButton', handleTripsButtonPress);
}
export const handleLogoutPress = function(event) {
localStorage.removeItem('jwt');
$('#logButton').replaceWith(`<a class="link is-info" id="logButton" href="Login/login.html"><button class="button is-success navbutton">Login</button></a>`);
}
export const handleTripsButtonPress = function(event) {
console.log("trips button")
let jwt = localStorage.getItem('jwt');
if (jwt && jwt != 'undefined') { // means user is logged in
window.location.replace('Trips/trips.html');
}
else {
localStorage.setItem('afterLogin','../Trips/trips.html');
window.location.replace('Login/login.html');
}
}
$(function () {
renderSite();
});