Guest User

Untitled

a guest
Aug 5th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. How can I check if a user is already logged in? (everyauth, node.js)
  2. var express = require('express')
  3. , everyauth = require('everyauth')
  4. , app = express.createServer();
  5. everyauth.helpExpress(app);
  6.  
  7. everyauth.loggedIn
  8.  
  9. var userlogin = function () {
  10. var req = this.request
  11. ,res = this.response
  12. ,login = req.body
  13. ,username = login.username
  14. ,password = login.password;
  15.  
  16. if(username === 'tester' && password === '12345'){
  17. req.session.user_id = xxxxxx;
  18. res.redirect('/');
  19. }else{
  20. res.redirect('/login');
  21. }
  22.  
  23. }
  24. var checkAuth = function(fn_auth, fn_unauth){
  25. var req = this.request
  26. ,res = this.response
  27. ,unauthCallback;
  28.  
  29. if(req.session.user_id){
  30. fn_auth(); //execute fn_auth if user is logged in. callback can be set to redirect to root path '/'
  31. }else{
  32. fn_unauth(); //execute fn_unauth calback which bring user to login path '/login'
  33. }
  34. }
  35. }
Add Comment
Please, Sign In to add comment