Login without all credentials passport - javascript

The problem is that in my User Schema I defined 3 inputs: name, surname and email. What if i want passport to make the user logged in only by email and password without writing name and surname?

There isn't a defined way to do sign in
And for your question no sign in is done by inputting everything found in userschema its normally email/username and password
As long as the inputs (email/username) are unique your good to go
To do that
Just search for the row where email:req.body.email
And then once you have this row compare do
If(row.password.equals(req.body.password)
If true do your cookie or whatever your gonna do

Related

Cognito user pool "username" appears as id not email, how to fix it?

I'm using Amazon Cognito user pools, and i choose to have users signup/In with their emails. According to online guides, when choosing so, the user pool should list users with "username" value as their email, but this is not the case, i'm seeing the "id" which is also referred to as "sub" as the "username" field!
it has the UUID format.
Any ideas how to get username shows the email?
** Note: I'm talking about showing users from AWS cognito console.
Attached is a screenshot
That seems to happen when you chose to signup with either email or phone.
Apparently in that configuration Cognito generates 'username' using the sub...
I would suggest configuring Congito to use 'username' and then on signup set up the 'username' to email, you can also pass email (and phone) as additional attributes.
I hope that helps
#Luke is correct, this only happens when you select the "Email address or phone number" option in the "How do you want your end users to sign in" section of the wizard.
It's a bit confusing because the SignUp API expects an email-formatted username during signup, but then ends up creating a user with a GUID as a username, and assigns the submitted username to the email attribute. This is described in the docs:
Call the SignUp API and pass an email address or phone number in the username parameter of the API. This API does the following:
If the username string is in valid email format, the user pool automatically populates the email attribute of the user with the username value.
If the username string format is not in email or phone number format, the SignUp API throws an exception.
The SignUp API generates a persistent UUID for your user, and uses it as the immutable username attribute internally. This UUID has the same value as the sub claim in the user identity token.
If the username string contains an email address or phone number that is already in use, the SignUp API throws an exception.
This is in fact probably what you want though, as it allows users to change their emails down the line (as actual usernames cannot be changed). And furthermore, the docs state that "You can use an email address or phone number as an alias in place of the username in all APIs except the ListUsers API", so the fact that the username is a GUID in the backend doesn't have much effect on how you interact with the API.
As for listing the email in the console, it looks like they've added an email column in the user list, so that shouldn't be a problem anymore.
Here you have an example.
auth.service.ts
you have to do the login method for Cognito in your authentication service. Something like this:
login(username: string, password: string): Promise<CognitoUser|any> {
return new Promise((resolve,reject) => {
Auth.signIn(username,password)
.then((user: CognitoUser|any) => {
this.currentUserSubject.next(user);
localStorage.setItem("currentUser", JSON.stringify(user));
localStorage.setItem("token", user.signInUserSession.idToken.jwtToken);
localStorage.setItem("userGroup", user.signInUserSession.idToken.payload['cognito:groups']);
localStorage.setItem("userEmail", user.attributes.email);
this.loggedIn = true;
resolve(user);
}).catch((error: any) => reject(error));
});
}
and then in the .ts of your component you have to do the call of that method in the constructor and store in a variable the userEmail argument that you get in the localStorage from Cognito:
constructor(
private authService: AuthService,
) {
this.authService.currentUser.subscribe(response => {
this.currentUser = response;
});
this.userSessionName = localStorage.getItem('userEmail');
}
Finally, you have to display the userSessionName variable in you .html component:
<p>{{ userSessionName }}</p>

Firebase-how to use a username along with google sign in?

I recently added google sign in with firebase to my website which already uses sign in with email and password. My website already has a lot of stuff involving their username (I have a separate database with email id and username, so I log them in using their email even if they give their username). So now, when a person signs in with google for the first time, it should save their google username and email in that database. How do I do this?
You can use the promisse return.
let provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/plus.login');
this.afAuth.auth.signInWithPopup(provider).then(user => console.log(user.email));
Or
this.afAuth.authState.take(1).subscribe(user => { console.log(user.email));

Meteor login email domain predefined

I want to make a Meteor app where users can only create an account if their email ends with #mydomain.com.
In the end, they would actually only need to enter their username and not the #mydomain.com part.
So, the create user field would look like:
Name: __________
eMail: __________#mydomain.com
Password: __________
Renter: __________
How would I go about doing this?
You use accounts package: meteor add accounts-password.
Then you would configure it in server-side code (http://docs.meteor.com/#accounts_config): Accounts.config({restrictCreationByEmailDomain:'mydomain.com'});
And then use Accounts.createUser in combination with custom UI that autofills the email domain part.
I'm assuming you're using Meteor's built-in accounts management packages. To limit signups to mydomain.com email addresses, put the following in server-side code:
Accounts.validateNewUser(function(user) {
if (/#mydomain\.com$/.test(user.emails[0].address.toLowerCase())) {
return true;
} else {
throw new Meteor.Error(403, "Email domain not allowed.");
}
});
As for helping them with adding the #mydomain.com, write some client-side code that validates the field in the login form where they enter their username. If it lacks an #, tack #mydomain.com onto the end of it before the form gets submitted.

Meteor js - "please re-enter your password to do that" - how to reauth while already logged in?

In Meteor, how do i check if some input password string matches the currently logged-in user's actual password? I'm looking to have certain more sensitive settings only be able to be changed if you re-enter your password, similar to how github does sensitive stuff.
In the application I'm working on, a shift manager will sign into the meteor app at the beginning of the day, and this unlocks the UI for employees / cashiers to use until the manager signs out. However, while the manager is doing something else, if an employee tries to, say, edit the cash drawer totals, they'll be prompted for the manager's password. If they enter an incorrect password, it just shouldn't let them do that operation, but it shouldn't log them out.
Where userPassword is the user submitted password. Note there is no underscore before id.
Meteor.loginWithPassword({id: localStorage['Meteor.userId'] }, userPassword, function (error) {
if(!error) {
// good to go.
} else {
// not this time, pal.
}
});

How to validate email To header?

I need to validate user input. The user can enter a full to header for an email message, so it may look like any of the following:
user#example.com
<user#example.com>
User <user#example.com>
"User" <user#example.com>
user#example.com, User2 <user2#example.com>
..etc. All of the above are valid To fields.
However, when user input is something like this:
user#example.com, not_an_email, User <user.example.com>
Then I want to respond with an error for the last 2 emails.
It's not a problem for me to check a plain email address for validity, but the extra String and braces <> I am a bit clueless about at the moment.

Categories