r/node • • Mar 25 '20

Authentication for API Routes using JWT and bcrypt (Theory + Code)

https://www.youtube.com/watch?v=j4Tob0KDbuQ&feature=share
84 Upvotes

15 comments sorted by

5

u/himurax3x Mar 25 '20

Recently used JWT, passport, bcrypt, and express and loved it to death.

2

u/bmvantunes Mar 25 '20

It's an awesome combo!!! Almost perfect! I can imagine how much you loved that time :)

For some reason, lately, I've found myself using https://nestjs.com/ quite a lot (the name is too similar with Next.js eheh)

Have you ever tried nestjs? If yes what do you think of it?

0

u/[deleted] Mar 25 '20

[deleted]

2

u/bmvantunes Mar 25 '20

I have never done ruby on rails - but I heard good things about it. Anything, in particular, you don't like? Or it's just a case of loving node.js more? :)

2

u/himurax3x Mar 26 '20

I like both a lot, i think moreso for exposure. But rails does a lot of the heavy lifting for you. Because of that its a great language for top experts in rails, and beginners, but i would so for someone in the middle, other framworks start to get more attractive

1

u/bmvantunes Mar 26 '20

You made really good points 🙂 I love to hear those experiences - thank you very much 😊😊😊

2

u/[deleted] Mar 26 '20

You should use argon2id, if not then scrypt, and finally if you have no other choice, bcrypt

1

u/bmvantunes Mar 26 '20

Thank you very much for the suggestion - I have to read more about it, but from an initial reading it seems better 😊

which npm package do you use normally? The best suggestion from npm search seems to be this one https://www.npmjs.com/package/argon2

2

u/[deleted] Mar 26 '20

Yeah that's the package that I use. Is very simply to use, the hash functions returns a string that contains the settings, hash, and salt, meaning if you changed the default settings afterwards, the previous hashes that you have created all still work perfectly!

1

u/bmvantunes Mar 26 '20

Awesome!!! I really appreciate your help, now I have a new "tool" to play around :D

I was reading some articles about argon2 and it is amazing!!! Once again, thank you for the suggestion u/hydroperox

Also... it seems easy to migrate from bcrypt to argon2, which is fantastic!!!

2

u/[deleted] Mar 26 '20

No worries, any issues or queries just message me!

5

u/Zarathustra420 Mar 26 '20

Howdy friend - what resource did you use for getting passport documentation?

The official passport docs are ROUGH. I've found good tutorials but (as tutorials) they're very opinionated.

3

u/[deleted] Mar 25 '20

It would be great if you can also do a video on how to persist auth tokens between page reloads, specifically with cookies.

1

u/bmvantunes Mar 25 '20

Thank you very much for the suggestion TheTorban - It's very high on my priority list after this Next.js series is over :)

If you have any other suggestion I would love to know :)

1

u/bmvantunes Apr 01 '20

Part 7 is now available. Consuming the APIs in server-side rendering: https://www.youtube.com/watch?v=sxwCxmKhhas