Creating a get key function
When it comes to encoding and decoding our token, we want to ensure that processes outside of the server cannot access details of the user of the token. We also do not want the frontend to have the opportunity to alter the token. To prevent altering or access to details in the token, the server uses a secret key to encode and decode the token, ensuring that the token is always encoded outside of the server as depicted in figure 9.1.

For our JWT, we are going to extract the token from the environment variables with the code below:
// glue/src/token.rs
pub fn get_key() -> Result<String, NanoServiceError> {
std::env::var("JWT_SECRET").map_err(|e| {
NanoServiceError::new(
e.to_string(),
NanoServiceErrorStatus::Unauthorized
)
})
}
We can see that we return an unauthorised error if we cannot get the environment variable because we cannot...