【发布时间】:2019-11-14 12:42:02
【问题描述】:
当他成功连接到 facebook 或 google 时,我需要重定向用户。 这是我的路线:
/*******************GOOGLE AUTH ROUTES********************* */
// auth with google+
router.get('/auth/google', passport.authenticate('google', {
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'
]
}));
// callback route for google to redirect to
// hand control to passport to use code to grab profile info
router.get('/auth/google/callback*', passport.authenticate('google'), (req, res) => {
resultats = {
"success": true,
"message": 'SUCCESS',
"result": req.user
}
res.json(resultats);
});
/*******************END GOOGLE AUTH********************* */
这是我的链接(fb/google):
<div className="rs-btn">
<a href={`${API}/auth/facebook`} target="_blank"className="btn facebook">
<FontAwesomeIcon icon={faFacebookF} />
</a>
<a href={`${API}/auth/google`} target="_blank"className="btn google">
<FontAwesomeIcon icon={faGoogle} />
</a>
</div>
最后是我的 config.js:
module.exports = {
jwtsecret : "fatboardauth",
session : {
cookieKey : "thisisthefatboardK2019eH67882019"
},
oauth : {
facebook : {
clientID : 737996303314074,
clientSecret : "06a5efdc93ebe7b84567874e4438d44d",
callbackURL : "http://localhost:3001/auth/facebook/callback"
},
google : {
clientID : "8216500008636-529u2au433fk80los8dtl841mvlab15q.apps.googleusercontent.com",
clientSecret : "XB7gZyHUKYGJFkZgo-YvITtDI",
redirect : "http://localhost:3001/auth/google/callback"
}
},
supportemail : "fatboarrestaurant@gmail.com",
gmailPSW : "myapp123!",
secretKey : "c2VjcmV0S2DFGBBN?ZmF0Ym9hcjIwMTk=",
schemes : 'http://',
};
例如,当用户在谷歌中连接时,我的浏览器中有这个:
{"success":true,"message":"SUCCESS","result":{"google":{"id":"112886936395081056197","email":"meryem.achemlal@gmail.com","name":"Achemlal Meryem"},"prenom":"Mem","nom":"Ach","tel":null,"dateCreation":"2019-11-13T18:45:58.69Z","datenaissance":null,"resetpasswordtoken":null,"resetpasswordexpires":null,"role":"user","enable":true,"_id":"5dcc4f7jh68861887ac259a","email":"mem.ache@gmail.com","__v":0}}
但我想要的是用户重定向到主页。 我怎么能用 react 做到这一点?
谢谢
【问题讨论】:
标签: node.js reactjs authentication routes