I am playing with deployd and am having trouble figuring out how to take the session info from one page to another. In the login demo on the deployd site they have some code to redirect a logged in user to a new page and welcome them. However if I visit that page normally in the url it is still visible if I dont use the login form. I assume this is just a very basic demo, but I would like to know how to deny a user if they haven't logged in and just try and visit the page.
Even some tips in the right direction will give me a lot of help, Thanks!
Here is my index page code
<body>
<section id="test"></div>
<form id="drop" >
User Name:<input id="user" type="text" name="username"><br>
Password<input id="pass" type="password" name="password"><br>
<input type="submit" value="login">
</form>
</body>
<script>
$(document).ready(function() {
dpd.things.get(function(result, error) {
$.each(result, function(i,result){
content = '<div class="'+result.name+'">' + '<p >' + result.name + '</p>' + '<p id="'+result.about+'">' + result.about + '</p>' + '</div>' ;
// about = '<p>' + result.about + '</p>';
$(content).appendTo("#test");
// $(about).appendTo("#about");
$('#test').attr('class', result.name);
$("#"+result.name).click(function() {
console.log(result);
dpd.things.del(result.id, function(well, error) {
$("."+result.name).remove();
}); }); }); }); });
$( "#drop" ).on( "submit", function( event ) {
event.preventDefault();
var hello = $("#user").val();
var goodbye = $("#pass").val();
dpd.users.login({"username": hello, "password": goodbye}, function(user, err) {
if(err) return console.log(err);
console.log(user);
location.href = "users.html";
}); });
</script>
and here is my users.html page js
<div class="container">
<h1></h1>
<button class="btn" id="logout-btn">Logout</button>
</div>
<script type="text/javascript" src="/js/lib/jquery.js"></script>
<script type="text/javascript" src="/dpd.js"></script>
<script type="text/javascript">
dpd.users.me(function(user) {
if (user) {
$('h1').text("Welcome, " + user.username + "!");
} else {
location.href = "/";
}
});
</script>