Adding authentication protection with Supabase
So far, we have organized our code so that the parts where we expect logged-in users to interact with our app are within the app/tickets/*
folder structure. That also means that every route that is only expected to be accessible to logged-in users will start with your-application.domain/tickets/*
. Since those routes all share the /tickets
parent path, we want to protect that path and all of its subpaths. Here, protecting means only allowing authenticated users to have access and redirecting everyone else.
However, before doing so, we have to create users and allow them to log in. Here’s what we will do now to achieve this:
- We will create our first users. Without users, we cannot use and test our application and protection.
- We will prepare the
middeware.js
file to make sure that authentication will work as expected. - With the login form we created earlier, we will allow the created users to log in by adding the...