fix: basic-auth compitibility issue (#2515)
This commit is contained in:
parent
17f438ac39
commit
8b054e6aac
@ -147,5 +147,26 @@ describe('actions', () => {
|
|||||||
});
|
});
|
||||||
expect(res.statusCode).toEqual(403);
|
expect(res.statusCode).toEqual(403);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should compitible with old api', async () => {
|
||||||
|
// Create a user without username
|
||||||
|
const userRepo = db.getRepository('users');
|
||||||
|
const email = 'test2@nocobase.com';
|
||||||
|
const password = '1234567';
|
||||||
|
await userRepo.create({
|
||||||
|
values: {
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const res = await agent.post('/auth:signIn').set({ 'X-Authenticator': 'basic' }).send({
|
||||||
|
email: 'test@nocobase.com',
|
||||||
|
password: '123456',
|
||||||
|
});
|
||||||
|
expect(res.statusCode).toEqual(200);
|
||||||
|
const data = res.body.data;
|
||||||
|
const token = data.token;
|
||||||
|
expect(token).toBeDefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -22,10 +22,13 @@ export class BasicAuth extends BaseAuth {
|
|||||||
if (!account && !email) {
|
if (!account && !email) {
|
||||||
ctx.throw(400, ctx.t('Please enter your username or email', { ns: namespace }));
|
ctx.throw(400, ctx.t('Please enter your username or email', { ns: namespace }));
|
||||||
}
|
}
|
||||||
|
const filter = email
|
||||||
|
? { email }
|
||||||
|
: {
|
||||||
|
$or: [{ username: account }, { email: account }],
|
||||||
|
};
|
||||||
const user = await this.userRepository.findOne({
|
const user = await this.userRepository.findOne({
|
||||||
filter: {
|
filter,
|
||||||
$or: [{ username: account || null }, { email: account || email }],
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
Loading…
Reference in New Issue
Block a user