pub async fn login(
    id: Identity,
    params: Json<LoginRequest>,
) -> Result<Json<bson::Document>, ApiError> {
    validate(&params)?;

    // Validate that the id + hashed password matches
    let hashed = hash(&params.password);
    let result = find_by_auth(&params.uid, &hashed).await;
    if result.clone().is_some() {
      // Create a JWT
      let user = result.clone().unwrap();
      let private_claim = PrivateClaim::new(user.uid, user.email.clone());
      let jwt = create_jwt(private_claim)?;
      
      // Remember the token
      let msg = doc! { "status" : "ok", "data" : jwt.clone().to_string() };
      id.remember(jwt);
      respond_json(msg)
    } else {
      let msg = doc! { "status" : "fail", "error" : "No UID" };
      respond_json(msg)
    }
}
/// Login a user
/// Create and remember their JWT
Login a user
Create and remember their JWT
Login a user Create and remember their JWT
pub async fn login(
    id: Identity,
    params: Json<LoginRequest>,
) -> Result<Json<bson::Document>, ApiError> {
    validate(&params)?;
    // Validate that the id + hashed password matches
    let hashed = hash(&params.password);
    let result = find_by_auth(&params.uid, &hashed).await;
    if result.clone().is_some() {
      // Create a JWT
      let user = result.clone().unwrap();
      let private_claim = PrivateClaim::new(user.uid, user.email.clone());
      let jwt = create_jwt(private_claim)?;
      // Remember the token
      let msg = doc! { "status" : "ok", "data" : jwt.clone().to_string() };
      id.remember(jwt);
      respond_json(msg)
    } else {
      let msg = doc! { "status" : "fail", "error" : "No UID" };
      respond_json(msg)
    }
}
pub async fn login ( id : Identity , params : Json < LoginRequest > , ) -> Result < Json < bson :: Document > , ApiError > { validate ( & params ) ? ; // Validate that the id + hashed password matches let hashed = hash ( & params . password ) ; let result = find_by_auth ( & params . uid , & hashed ) . await ; if result . clone ( ) . is_some ( ) { // Create a JWT let user = result . clone ( ) . unwrap ( ) ; let private_claim = PrivateClaim :: new ( user . uid , user . email . clone ( ) ) ; let jwt = create_jwt ( private_claim ) ? ; // Remember the token let msg = doc ! { " " " " " " jwt clone ( ) to_string ( ) } ; id . remember ( jwt ) ; respond_json ( msg ) } else { let msg = doc ! { " " " " " " " " } ; respond_json ( msg ) } }
Login a user
Create and remember their JWT
Login a user Create and remember their JWT
id
Identity
params
Json<LoginRequest>