Implementing authentication with hooks
We’ve already utilized Fastify plugins to organize routes and enhance the maintainability of our project, but these are just some of the advantages that the Fastify plugin system provides. The key features of the plugin system are as follows:
- Encapsulation: All the hooks, plugins, and decorators added to a plugin are bound to the plugin context, ensuring they remain encapsulated within the plugin’s scope.
- Isolation: Each plugin instance is self-contained and operates independently, avoiding any modifications to sibling plugins. This isolation ensures that changes or issues in one plugin do not affect others.
- Inheritance: A plugin inherits the configuration of its parent plugin, allowing for a hierarchical and modular organization of plugins, making it easier to manage complex application structures.
These concepts might appear complex at first, but in this recipe, we will put them into practical use. Specifically...