Skip to content

Commit

Permalink
Do not include "email": null in JWT (if there is no email) (#964)
Browse files Browse the repository at this point in the history
Just a tiny thing I noticed recently. ~~Note for testing: `jose` does
not have an email, everyone else does.~~ nevermind, Jose is not allowed
to request JWTs... mhpf.
  • Loading branch information
owi92 authored Oct 20, 2023
2 parents 637709c + cabdca0 commit bd6d6b6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions backend/src/auth/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ impl JwtContext {
+ chrono::Duration::from_std(self.config.expiration_time)
.expect("failed to convert from std Duration to chrono::Duration");

let payload = json!({
let mut payload = json!({
"name": user.display_name,
"username": user.username,
"email": user.email,
"exp": exp.timestamp(),
});
if let Some(email) = &user.email {
payload.as_object_mut().unwrap().insert("email".into(), email.clone().into());
}


self.encode(&payload)
}
Expand Down

0 comments on commit bd6d6b6

Please sign in to comment.