akveo / akveo/ngx-admin-bundle-support

Can't log-in using the latest node-ecom bundle

未關閉
#68 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
TypeScript
星號
56
分支
30
PR 合併指標
30 天內沒有已合併 PR

描述

I have slip-streamed the latest version of the node-ecom bundle back-end into my pre-existing project. If I use a pre-existing JWT token, I can access data through the various API endpoints, but I can't get "login" to work.

The relevant code in my authController.js file looks like this:

```
*
* Copyright (c) Akveo 2019. All Rights Reserved.
* Licensed under the Single Application / Multi Application License.
* See LICENSE_SINGLE_APP / LICENSE_MULTI_APP in the 'docs' folder for license information on type of purchased license.
*/

const express = require('express');
const passport = require('passport');

const cipher = require('../auth/cipherHelper');
const AuthService = require('./authService');

const router = express.Router();
const authService = new AuthService();
const auth = passport.authenticate('jwt', { session: false });

router.post('/login', (req, res) => {
passport.authenticate('local', { session: false }, (err, user) => {
if (err || !user) { //this branch is always taken even with valid email/password
console.log("authenticate issue");
console.log(err);
console.log(user);
return res.status(401).send({
error: err ? err.message : 'Login or password is wrong',
});
}
req.login(user, { session: false }, (error) => {
console.log("login issue");
if (error) {
res.send(error);
}

const response = { token: cipher.generateResponseTokens(user) };
res.send(response);
});
})(req, res);
});
```

When accessing the API via the Swagger UI (or externally from Postman or my front end) the `if (err || !user)` condition is always true because always:

`err` = null
`user` = false

Can someone give me a pointer as to where to check for errors upstream in my code as it seems the `passport.authenticate` function may not be returning the values that are expected.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。