Skip to content

Commit 840c85f

Browse files
closer to logging out
1 parent a6d3b73 commit 840c85f

File tree

8 files changed

+47
-23
lines changed

8 files changed

+47
-23
lines changed

app/auth/auth.router.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ function createJwtToken(user) {
2626
});
2727
}
2828
//Login endpoint
29-
authRouter.get('/login.html', (req, res) => {
29+
authRouter.get('/login.html', (req, res) => {});
3030

31-
32-
});
3331
authRouter.post('/login', localPassportMiddleware, (request, response) => {
3432
const user = request.user.serialize();
3533
const jwtToken = createJwtToken(user);
@@ -51,7 +49,14 @@ authRouter.post('/refresh', jwtPassportMiddleware, (request, response) => {
5149
});
5250
});
5351

54-
authRouter.post('/logout', localPassportMiddleware, (req, res) => {
55-
res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
56-
});
57-
module.exports = {authRouter};
52+
authRouter.get('/logout', localPassportMiddleware, (req, res) => {
53+
console.log("logging out")
54+
res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
55+
res.json({
56+
jwtToken,
57+
user
58+
})
59+
});
60+
module.exports = {
61+
authRouter
62+
};

public/auth.page.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// All these modules are are defined in /public/utilities
22
const RENDER = window.RENDER_MODULE;
3-
const HTTP = window.HTTP_MODULE;
4-
const CACHE = window.CACHE_MODULE;
3+
// const HTTP = window.HTTP_MODULE;
4+
// const CACHE = window.CACHE_MODULE;
55

66
$(document).ready(onPageLoad);
77

88
function onPageLoad() {
99
$('#sign-up-form').submit(onSignUpSubmit);
1010
$('#login-form').submit(onLoginSubmit);
11+
$('#logout-btn').on('click', onLogoutSubmit);
12+
1113
}
1214

1315
function onSignUpSubmit(event) {
@@ -55,4 +57,20 @@ function onLoginSubmit(event) {
5557
alert('Incorrect username or password. Please try again.');
5658
}
5759
});
60+
}
61+
62+
function onLogoutSubmit(event) {
63+
console.log("Logging out")
64+
event.preventDefault();
65+
HTTP.logoutUser({
66+
67+
onSuccess: response => {
68+
const authenticatedUser = response.user;
69+
console.log(authenticatedUser);
70+
authenticatedUser.jwtToken = response.jwtToken;
71+
CACHE.deleteAuthenticatedUserFromCache(authenticatedUser);
72+
alert('Please come again');
73+
window.open('/', '_self');
74+
}
75+
})
5876
}

public/css/main.css

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ max-width:370px;
364364
}
365365

366366
.tt-dropdown-menu {
367-
width: 422px;
367+
width: 100%;
368368
margin-top: 3px;
369369
padding: 8px 0;
370370
background-color: #fff;
@@ -396,10 +396,9 @@ max-width:370px;
396396
text-align: left;
397397
}
398398

399-
400-
/* .twitter-typeahead {
401-
width: 100%;
402-
} */
399+
.twitter-typeahead {
400+
width: 75%;
401+
}
403402

404403

405404
/* Date Navigation */

public/home.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<header class="header">
1818
<div class="logo">Fit-Journal</div>
1919
<nav class="nav-login">
20-
<a id="logout-btn" href="">Log Out</a>
20+
<a href="" id="logout-btn" type="submit">Log Out</a>
21+
2122
</nav>
2223
</header>
2324

@@ -91,9 +92,11 @@ <h4 class="add-ex js-addEx"><a href="#">Add Exercise</a></h4>
9192
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
9293
<script src="/moment.js"></script>
9394
<script src="/utilities/cache.module.js"></script>
95+
<script src="/auth.page.js"></script>
9496
<!-- <script src="../utilities/render.module.js"></script> -->
9597
<script src="/utilities/http.module.js"></script>
9698
<script src="/index.page.js"></script>
99+
97100
<script src="/utilities/index.js"></script>
98101
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
99102
<script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>

public/home.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function onPageLoad() {
1616
// });
1717
// }
1818
{ /* <nav class="nav-login"><a id="logout-btn" href="">Log Out</a> </nav> */ }
19-
$('body').on('click', '#logout-btn', onLogoutBtnClick());
19+
2020
// $('#workout-list').on('click', '#delete-workout-btn', onDeleteWorkoutBtnClick);
2121
// $('#workout-list').on('click', '#workout-card', onWorkoutCardClick);
2222
}

public/search.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</div>
3131
<div class="set-wkout">
3232
<form action="/api/workout" class="js-setworkOut" method="POST">
33-
<h3 class="exerciseName "></h3>
33+
<h3 class="exerciseName"></h3>
3434
<div class="set-input">
3535
<label id="reps-lbl" for="POST-reps">Number of reps:</label>
3636
<input id="POST-reps" type="text" name="reps">

public/search.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ function clearInput() {
5858
function selectExercise() {
5959
$('.search-btn').on('click', function() {
6060
let searchVal = $('.search-ex').val();
61-
$('.exerciseName').html(`${searchVal}`);
61+
console.log(searchVal)
62+
// $('.exerciseName').append(`${searchVal}`);
6263
});
6364

6465
}
@@ -67,8 +68,7 @@ function showSetAdd() {
6768

6869
}
6970

70-
function
71-
// save to workout
71+
7272

7373

7474
function onPageLoad() {

public/utilities/http.module.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ window.HTTP_MODULE = {
77
createWorkout,
88
updateWorkout,
99
deleteWorkout,
10+
logoutUser
1011

1112
};
1213

@@ -61,14 +62,12 @@ function loginUser(options) {
6162

6263
function logoutUser(options) {
6364
console.log("logout user called")
64-
axios.post('')
65-
.then()
66-
.catch()
6765
const {
6866
userData,
6967
onSuccess,
7068
onError
7169
} = options;
70+
7271
$.ajax({
7372
type: 'POST',
7473
url: '/api/auth/logout',

0 commit comments

Comments
 (0)