Skip to content

Commit 4321d56

Browse files
authored
Merge pull request Human-Connection#20 from Human-Connection/bugfix/email-case-sensitive
fix login email case sensitive bug
2 parents bccc49a + b36f7b2 commit 4321d56

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

server/authentication.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const authentication = require('feathers-authentication');
22
const jwt = require('feathers-authentication-jwt');
33
const local = require('feathers-authentication-local');
4+
const { lowerCase } = require('feathers-hooks-common');
45

56
module.exports = function () {
67
const app = this;
@@ -17,6 +18,7 @@ module.exports = function () {
1718
app.service('authentication').hooks({
1819
before: {
1920
create: [
21+
lowerCase('email', 'username'),
2022
authentication.hooks.authenticate(config.strategies)
2123
],
2224
remove: [

server/services/auth-management/auth-management.hooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const isEnabled = require('../../hooks/is-enabled');
22
const { authenticate } = require('feathers-authentication').hooks;
3-
const commonHooks = require('feathers-hooks-common');
3+
const { iff } = require('feathers-hooks-common');
44

55
const isAction = () => {
66
let args = Array.from(arguments);
@@ -13,7 +13,7 @@ module.exports = {
1313
find: [],
1414
get: [],
1515
create: [
16-
commonHooks.iff(
16+
iff(
1717
isAction('passwordChange', 'identityChange'),
1818
[
1919
authenticate('jwt'),

server/services/users/users.hooks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ module.exports = {
109109
...restrict,
110110
hashPassword(),
111111
disableMultiItemChange(),
112+
lowerCase('email', 'username'),
112113
when(isProvider('external'),
113114
restrictUserRole()
114115
),
@@ -118,6 +119,7 @@ module.exports = {
118119
...restrict,
119120
// hashPassword(),
120121
disableMultiItemChange(),
122+
lowerCase('email', 'username'),
121123
// Only set slug once
122124
when(
123125
hook => {

test/services/authentication.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const assert = require('assert');
2+
const app = require('../../server/app');
3+
const service = app.service('authentication');
4+
const userService = app.service('users');
5+
6+
describe('\'authentication\' service', () => {
7+
before(function(done) {
8+
this.server = app.listen(3031);
9+
this.server.once('listening', () => done());
10+
});
11+
12+
after(function(done) {
13+
this.server.close(done);
14+
});
15+
16+
beforeEach(async () => {
17+
await app.get('mongooseClient').connection.dropDatabase();
18+
});
19+
20+
afterEach(async () => {
21+
await app.get('mongooseClient').connection.dropDatabase();
22+
});
23+
24+
it('registered the service', () => {
25+
assert.ok(service, 'Registered the service');
26+
});
27+
28+
it('user can register', async () => {
29+
const user = await userService.create({
30+
31+
password: '1234',
32+
name: 'Peter',
33+
role: 'admin'
34+
});
35+
36+
assert.ok(user, 'user successfully registered');
37+
});
38+
39+
it('user can login', async () => {
40+
await userService.create({
41+
42+
password: '1234',
43+
name: 'Peter',
44+
role: 'admin'
45+
});
46+
const params = {
47+
provider: 'socketio'
48+
};
49+
const { accessToken } = await service.create({
50+
strategy: 'local',
51+
52+
password: '1234',
53+
}, params);
54+
55+
assert.ok(accessToken, 'user successfully logged in');
56+
});
57+
58+
it('ignores uppercase letters on login', async () => {
59+
await userService.create({
60+
61+
password: '1234',
62+
name: 'Peter',
63+
role: 'admin'
64+
});
65+
const params = {
66+
provider: 'socketio'
67+
};
68+
const { accessToken } = await service.create({
69+
strategy: 'local',
70+
71+
password: '1234',
72+
}, params);
73+
74+
assert.ok(accessToken, 'uppercase letters are ignored');
75+
});
76+
});

0 commit comments

Comments
 (0)