我希望Auth0能够区分社交注册和社交登录。如果新用户在注册之前尝试登录社交网站,AUTH0应该会响应错误,并要求用户先注册。如今,如果用户在没有注册的情况下登录社交网站,AUTH0会将其视为注册。
exports.google_LogIn = function(req, res, next) {
passport.authenticate("google", {
scope: ["profile", "email"]
})(req, res, next);
}发布于 2020-02-01 16:33:59
您的Passport策略允许您返回用户或错误。
例如,如果您的数据库以前没有见过该用户(使用Mongoose),那么这个Google策略将返回一个错误。
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://www.example.com/auth/google/callback"
},
function(accessToken, refreshToken, profile, done) {
User.findOne({ googleId: profile.id }, function (err, user) {
if (!user) return done(Error("needs signup"), null)
return done(err, user)
});
}
));在回调路径中,您可以给Passport一个failureRedirect,以便在出现错误时将用户发送到您的注册页面。
app.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/signUpPage' }),
function(req, res) {
res.redirect('/');
});https://stackoverflow.com/questions/60015009
复制相似问题