Restricting access to the data
Our app is now protected by authentication, but we still need to make sure that the user can only see their own to-do items. To do this, we need to modify our app so that for each to-do item, we also store the user ID that created the to-do, effectively associating each to-do item with a user. Once we have that, we’ll need to further modify our code to only retrieve the to-do items that belong to the currently logged-in user.
Adding the user ID to the to-do items
In order to associate each to-do item with a user, we need to add a new column to the todos
table. This means we’ll need to create a new migration. Let’s do that by running the following command in the Genie REPL:
julia> using SearchLight julia> SearchLight.Migration.new("add column user_id to todos")
This will create a new migration, AddColumnUserIdToTodos
– let’s edit it to put in our logic. In the db/migrations/
folder, open the...