Building a Secure Web Application with .NET 8, Supabase, Vue.js 3 and AG Grid
Introduction
In this guide, we will create a web application named TravelBlog. The tutorial begins by setting up authentication and managing data through Supabase. We will then develop a .NET 8 Web API to handle users and roles provided by Supabase. Lastly, we'll build the user interface using Vue.js 3 and integrate AG Grid for efficient data display and management on the frontend. The guide also demonstrates securing the application with JWT (JSON Web Token) for authentication and authorisation.
Prerequisites
Before starting, make sure you have the following:
Introduction to Supabase
Supabase is an open-source backend-as-a-service platform designed to simplify web and mobile application development. It provides a suite of tools and services, including authentication, database management, real-time updates, and cloud functions, all built on top of PostgreSQL.
Supabase integrates a robust authentication system directly with PostgreSQL, enabling seamless user management and data security. Here's how it works:
The authorisation system in a Supabase backed application often involves a few key tables to manage users, roles, and permissions. Here's a summary of used tables in TravelBlog:
These tables work together to create a robust and scalable authorisation system. By combining Supabase's built-in authentication features with custom tables for roles and permissions, we can implement detailed access control policies and ensure data security at the application level.
After setting up the database schema, custom SQL functions can streamline user management tasks and enhance JWT customisation. These functions can automatically handle user-related operations and ensure the JWT includes relevant information, such as user roles.
1. Automating Profile Creation
When a new user registers, you can automatically create a corresponding profile entry using a database trigger and function.
2. Including Role in JWT Tokens
To include the user's role in the JWT, you can use what is called Web Hook in Supabase and call from there a Postgres function that retrieves the role from the roles table and appends it to the token payload.
Other helpful functions include:
These custom functions and triggers help automate routine operations and enrich the JWT payload, resulting in a more efficient and secure application.
Setting up the .net solution
The .NET Web API serves as the backend layer, exposing endpoints that interact with data managed in Supabase. This architecture allows the Web API to act as a bridge between the frontend and the Supabase backend, consuming its services for authentication, data retrieval, and updates.
Key Features of the .NET Web API
Benefits of this Approach are:
领英推荐
This design ensures a robust, secure, and scalable system, making the Web API a critical component in the overall architecture.
Setting up the UI solution
At the core of TravelBlog’s user interface (UI) lies VueJS 3, a progressive JavaScript framework known for its reactivity and component-based architecture. By leveraging VueJS 3, the developers have crafted a highly interactive and dynamic UI that adapts seamlessly to user inputs. Here’s what makes the TravelBlog interface remarkable:
What the app can do so far?
At the moment of writing, the following core functionalities are available:
With these foundational features in place, TravelBlog is shaping up to be a comprehensive platform for the travel community. Future updates are expected to bring even more functionality and interactivity to the platform.
References and Acknowledgments
I would like to extend my gratitude to the following resources and contributors:
It’s also worth mentioning the following videos that inspired me to write this article and begin the development of TravelBlog:
How to start with VueJS:
Supabase tutorials:
Special thanks to the open-source community for their invaluable contributions and for sharing knowledge that made this project possible. A heartfelt thanks to Kam for generously sharing his expertise and providing invaluable support in helping me get acquainted with Supabase and Vue.
GitHub Repository
The source code for this project is available on GitHub. If you’re interested in contributing to the development of future features for TravelBlog, I would be delighted to have your support! Your ideas, feedback, and code contributions are highly appreciated and play a crucial role in improving the application.
Feel free to explore the repository, raise issues, and submit pull requests. Together, we can make TravelBlog even better!