Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How can I check if a user is already logged in? (everyauth, node.js)
- var express = require('express')
- , everyauth = require('everyauth')
- , app = express.createServer();
- everyauth.helpExpress(app);
- everyauth.loggedIn
- var userlogin = function () {
- var req = this.request
- ,res = this.response
- ,login = req.body
- ,username = login.username
- ,password = login.password;
- if(username === 'tester' && password === '12345'){
- req.session.user_id = xxxxxx;
- res.redirect('/');
- }else{
- res.redirect('/login');
- }
- }
- var checkAuth = function(fn_auth, fn_unauth){
- var req = this.request
- ,res = this.response
- ,unauthCallback;
- if(req.session.user_id){
- fn_auth(); //execute fn_auth if user is logged in. callback can be set to redirect to root path '/'
- }else{
- fn_unauth(); //execute fn_unauth calback which bring user to login path '/login'
- }
- }
- }
Add Comment
Please, Sign In to add comment