Authentication in Node.js - #4 Registration

Veröffentlicht am: 25 Dezember 2019
auf dem Kanal: Code Realm
12,812
191

In this video, we're going to tackle the first core feature of user authentication, that is registration. When signing up with our app, a user would need to submit some personal data, which we're going to validate with Joi. @hapi/joi is a library for server-side validation with a very expressive and elegant API. We'll also have a bit of custom logic to check for the existence of a user account by its email address.

An important thing to note is that email addresses are effectively case-insensitive, since most email providers will cast the mailbox name to lowercase. As such, the email will most likely get delivered regardless of the casing. In our application, data integrity is a must, so we need to avoid mixed casing as it enables users to sign up repeatedly with the same email address. We'll also come back to password validation and hashing in just a bit. As a reminder, never store plaintext passwords in your database!

One last touch we'll add is middleware. Borrowing Laravel's vernacular, we'll attach guest (and soon auth) middleware to our register endpoint. At this point, we'd be able to initiate user sessions and issue session cookies upon successful registration. You'll notice that repeated sign up requests cause the server to hang up. That's because we need to wrap async code with try-catch and forward any errors to Express using the next function. We'll address this issue with error handling in the very next video.

As mentioned before, please be sure to review Session Authentication in Express    • Session Authentication in Express   before watching this, as I'll be jumping over express-session assuming you've already seen how to use it from the older tutorials on the channel. It goes without saying, but please be sure to also follow along with the previous videos in the series, as they build up on each other (see the playlist).

@hapi/joi https://www.npmjs.com/package/@hapi/joi (used to be joi up until v15)

mongoose https://www.npmjs.com/package/mongoose

Project repo https://github.com/alex996/node-auth


Auf dieser Seite können Sie das Online-Video Authentication in Node.js - #4 Registration mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Code Realm 25 Dezember 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 12,812 Mal angesehen und es wurde von 191 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!