-
Book Overview & Buying
-
Table Of Contents
Rust Web Programming
By :
For our users, we are going to have to enable them to log in. This means that we have to create an endpoint to check their credentials, and then generate a JWT to be returned back to the user in the frontend via the header in the response. Our first step is to define a login schema in the src/json_serialization/login.rs file with the following code:
use serde::Deserialize;
#[derive(Deserialize)]
pub struct Login {
pub username: String,
pub password: String
}
We have to remember to register it in the src/json_serialization/mod.rs file with the pub mod login; line of code. Once we have done this, we can build our login endpoint. We can do this by editing the src/views/auth/login.rs file we created in Chapter 3, Handling HTTP Requests, in the Managing views using the Actix-Web framework section, which declares our basic login view. This just returns a string.
Now, we can start refactoring this view by defining...