Cleaning up authentication requirements
In this section, we are going to clean up our Rust server in terms of authentication before we start configuring our frontend to handle these authentication processes. To keep the flow of the chapter engaging, we have not regularly carried out “housekeeping.” Now, we are going to update our to_do
views. We can start by updating the create
view with authentication requirements. To do so, the function signature of our create
view in the src/views/to_do/create.rs
file should look like the following:
. . . use crate::jwt::JwToken; use crate::database::DB pub async fn create(token: JwToken, req: HttpRequest, db: DB) -> HttpResponse { . . .
We also must update the user ID when creating a new item with the ID from the token, using the following code:
if items.len() == 0 { ...