Restructuring our JWT
Our JWT now needs to house the unique ID of the user, have encoding/decoding functions, and update the FromRequest
trait implementation. The main definition of our JWT struct has the following outline:
// glue/src/token.rs
#[derive(Debug, Serialize, Deserialize)]
pub struct HeaderToken {
pub unique_id: String
}
impl HeaderToken {
pub fn get_key() -> Result<String, NanoServiceError> {
. . .
}
pub fn encode(self) -> Result<String, NanoServiceError> {
. . .
}
pub fn decode(token: &str) -> Result<Self, NanoServiceError> {
. . .
}
}
We will cover the code inside those encoding/decoding functions in the following subsections. Finally, we recall that the outline for the FromRequest
trait implementation takes the form below:
// glue/src/token.rs
#[cfg(feature = "actix")]
impl FromRequest for HeaderToken {
type Error = NanoServiceError;
type Future = Ready<Result<...