【发布时间】:2018-02-20 01:36:02
【问题描述】:
我试图在用户登录后获取 user.id,但我无法弄清楚。
当我在 Postman (../api/users/829ug309hf032j) 中执行硬 GET 请求时,我得到了该用户,但我不知道如何在 GET 请求之前获取要设置的 ID。
app.component.ts
const id = // id I need of logged-in user //;
this.http.get('http://localhost:3000/api/users/' + id).subscribe(data => {
console.log(data)
});
server.js
app.get('/api/users/:id', (req, res) => {
User.findById(req.params.id, (err, users) => {
res.send(users)
})
})
app.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/ask' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/answer');
});
我想向用户显示他们的姓名,并且仅在他们登录时才显示...
<p *ngIf="user">{{ user.name }}</p>
【问题讨论】:
标签: angular express passport.js backend