我是Angular.js的新手并尝试为网站构建本地身份验证.我已经浏览了各种来源,单页应用程序中的身份验证非常有用.当我尝试在我的localhost中构建相同的代码时,我的代码进入循环.
app.post('/login',.....)在响应返回用户,但之后,尽管加载它是检查用户是否通过调用记录在管理页面 app.get('/loggedin',... ),并req.isAuthenticated()正在恢复false,即使登录后,它进入一个循环.我不明白为什么会这样,请帮助我.
服务器端代码
var express = require('express');
var http = require('http');
var path = require('path');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
//==================================================================
// Define the strategy to be used by PassportJS
passport.use(new LocalStrategy(
function(username, password, done) {
if (username === "admin" && password === "admin") // stupid example
return done(null, {name: "admin"});
return done(null, false, { message: 'Incorrect username.' });
}
));
// Serialized and deserialized methods when …Run Code Online (Sandbox Code Playgroud)