Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unique email not working while create #572

Closed
SeaDog505 opened this Issue Sep 17, 2017 · 11 comments

Comments

Projects
None yet
3 participants
@SeaDog505
Copy link

SeaDog505 commented Sep 17, 2017

Hi, for example I created a below code in my index.html

var User = {
  email: 'admin@feathersjs.com',
  password: 'admin',
  permissions: ['*']
};

app.service('auth').create(User).then(user => {
  console.log('Created default user', user);
}).catch(console.error);

I don't know why but after each page refresh create is new user. My schema model look like below:

module.exports = function (app) {
  const mongooseClient = app.get('mongooseClient');
  const auth = new mongooseClient.Schema({
  
    email: { type: String, unique: true, dropDups: true, required : true },
    password: { type: String, required : true },
    permissions: { type: String },
  
  
    createdAt: { type: Date, default: Date.now },
    updatedAt: { type: Date, default: Date.now }
  });

  return mongooseClient.model('auth', auth);
};

On the occasion why my collection name here is auth and after create an user is auths?

@SeaDog505 SeaDog505 changed the title unique email not working unique email not working while create Sep 17, 2017

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Sep 17, 2017

What module versions are you using? Is there error messages?

@SeaDog505

This comment has been minimized.

Copy link
Author

SeaDog505 commented Sep 18, 2017

I have feathes-cli version 2.3.7 any error message.

version modules:
feathers-authentication-client@^0.3.1:
feathers-authentication-hooks@^0.1.4:
feathers-authentication-jwt@^0.3.2:
feathers-authentication-local@^0.4.4:
feathers-authentication@^1.2.7:

Something is wrong, I created previously one user and next I received a message that the user exists. Now after each page refresh is create new user. Script not checks if user exists but after changed db.collection from auth on eg. users I can create only one user with the same email. The second time I receive a message: "email: admin@feathersjs.com" already exists."
I don't understand that. I dropped my collection and I dropped my DB. The problem is the same.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Sep 18, 2017

We need an example application to look at and reproduce the problem.

@SeaDog505

This comment has been minimized.

Copy link
Author

SeaDog505 commented Sep 19, 2017

I know what was a problem probably. I launched my application, then I refreshed a page and is created a new user. Then I had to remove db without stopped the application. In this moment I refreshed a page and each next refresh has been creating a new user without checks if user already exists. I don't stopped the app! I'm checking now and I see that when I drop db or collection and I stop app and it relaunch I can add only one the same user. Can you explain me why I have to stoped the app before db.dropDatabase()? Tell me too why my collection in schema is "auth" and in mongo I see "auths" while "auth" collection exists too but is some other data there like:

db.auth.find({});
2017-09-19T12:31:22.327+0200 TypeError: Object function () {
var ex;
try {
this._authOrThrow.apply(this, arguments);
} catch (ex) {
print(ex);
return 0;
}
return 1;
} has no method 'find'

and this is my auths.collection();

db.auths.find({});
{ "_id" : ObjectId("59c0f1a1c1954516c0d90e00"), "email" : "admin@example.com", "password" : "$2a$12$/T6TdscpYVO.XvAWwXI.R.yNvsOGMY0L2XWEfAsfvbXIZ3ZDNG922", "permissions" : "*", "updatedAt" : ISODate("2017-09-19T10:29:53.850Z"), "createdAt" : ISODate("2017-09-19T10:29:53.850Z"), "__v" : 0 }

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Sep 19, 2017

I think the auth vs. auths name is a mistake on your side. The generator will not change db or collection names. Dropping a database from under a running application without restarting it is always a case that can cause tons of issues.

@SeaDog505

This comment has been minimized.

Copy link
Author

SeaDog505 commented Sep 20, 2017

I created new DB, then I launched this application. After launched the application in mongoDB I see that DB it was created and when I use this DB and I execute the command: show collection(); I see auths collection and system.indexes. I don't see auth collection but if I execute an command: db.auth.find({}); I receive this result:

db.auth.find({});
2017-09-20T13:27:00.412+0200 TypeError: Object function () {
var ex;
try {
this._authOrThrow.apply(this, arguments);
} catch (ex) {
print(ex);
return 0;
}
return 1;
} has no method 'find'
db.auths.find({});

I created new application too and I have the same issue. I didn't do nothing in mongo. This is default configuration without the password too. Maybe you try create a service authentication with default change users service on auth?

  • I see in my other project (other DB) the same case. After first launched application is created hidden auth collection therefore my auth collection name is rename on auths but why is this collection hidden and is create automatically?
@daffl

This comment has been minimized.

Copy link
Member

daffl commented Sep 21, 2017

As I mentioned before, without a reproducible example it is almost impossible for us to figure out what is happening here.

@SeaDog505

This comment has been minimized.

Copy link
Author

SeaDog505 commented Sep 25, 2017

I understand, OK. Below is my config file:

{
"host": "localhost",
"port": 3030,
"public": "../public/",
"paginate": {
"default": 10,
"max": 50
},
"authentication": {
"secret": "My secret key",
"strategies": [
"jwt",
"local"
],
"path": "/authentication",
"service": "auth",
"jwt": {
"header": {
"type": "access"
},
"audience": "https://yourdomain.com",
"subject": "anonymous",
"issuer": "feathers",
"algorithm": "HS256",
"expiresIn": "1d"
},
"local": {
"entity": "user",
"usernameField": "email",
"passwordField": "password"
}
},
"mongodb": "mongodb://localhost:27017/MyDatabase"
}

I noticed, that after first launched application is created hidden auth collection. I can have empty index.html, js file, whatever. Does not matter. First launched my application is changed my collection while in my config is auth.

I think that hidden auth collection is booked by mongoDB. I can't show you any example because I have only bootstrap login form. I don't have any js script. I'm running an application and I'm checking my DB and I see "auths" collection instead "auth".

@teddest

This comment has been minimized.

Copy link

teddest commented Sep 27, 2017

I'm experiencing the same issue.

Here are the steps I took to reproduce scaffolding an app from scratch.

NodeJS v8.1.2
FeathersJS 2.3.3
RethinkDB 2.3.6

$ feathers generate app
? Accept defaults...

$ feathers generate authentication
? What authentication providers do you want to use? Other PassportJS strategies not in this list can
still be configured manually. Username + Password (Local)
? What is the name of the user (entity) service? users
? What kind of service is it? RethinkDB
? What is the database connection string? rethinkdb://localhost:28015/smart_garden

curl 'http://localhost:3030/users/' -H 'Content-Type: application/json' --data-binary '{ "email": "feathers@example.com", "password": "secret" }'
curl 'http://localhost:3030/users/' -H 'Content-Type: application/json' --data-binary '{ "email": "feathers@example.com", "password": "secret" }'
curl 'http://localhost:3030/users/' -H 'Content-Type: application/json' --data-binary '{ "email": "feathers@example.com", "password": "secret" }'
curl 'http://localhost:3030/users/' -H 'Content-Type: application/json' --data-binary '{ "email": "feathers@example.com", "password": "secret" }'

I verified that 4 documents were created with the same email and password.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Sep 27, 2017

RethinkDB does not support unique constraints. You will have to check yourself in a before hook if the email already exists. This also applies to MongoDB (you have to add a unique constraint on the email).

I'm going to close this issue since there is not much more debugging we can do without a complete repository to reproduce the original problem.

@daffl daffl closed this Sep 27, 2017

@SeaDog505

This comment has been minimized.

Copy link
Author

SeaDog505 commented Sep 27, 2017

OK, Daff my problem had resolved previously. Now I wanted to understand why after first launched my application my collection name "auth" is changed on "auths" however the main question is other than my second question we can close this issue. We know that my problem was on me side. I not stopped the application. Regarding the second problem I named my authentication service like users (default) and everything is all right. I think the mongoDB has "auth" collection for authenticate their users therefore a collection name "auth" is changed on "auths". This is no matter already. Thanks for replies and the conversation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.