Menu

Authentication and authorization — Fastify with TypeScript (part 12/18)
📰

Authentication and authorization — Fastify with TypeScript (part 12/18)

DEV Community: fastify·Antonio Tripodi·9 days ago
#kipOcEY4
#devtofastify#devto#dev#fastify#user
Long article (2484 words) — no AI summary yet.
Reading 0:00
15s threshold

Authentication and authorization

Twelfth chapter of the "Fastify with TypeScript" series. Let's put together plugins, hooks, decorators and error handling to build a complete JWT authentication system with role-based access control. By the end, users will have hashed passwords, a login route will hand out tokens, and two of our routes will require one.

npm install @fastify/jwt argon2

Enter fullscreen mode

Exit fullscreen mode

@fastify/jwt signs and verifies JSON Web Tokens. argon2 hashes passwords with Argon2id. It is a binding to the reference implementation of the algorithm, written in C, and it does the work off the main thread, so hashing doesn't block the event loop. The package ships prebuilt binaries for Linux (including Alpine), Apple Silicon Macs and Windows, so on those systems there is nothing to compile; elsewhere npm install builds it and needs a C++ compiler.

Storing a password hash

Never store a password.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.