auth: Introduce User struct

The `UserClaims` structure is an implementation detail of how the JWT
encoding process works.  We do not need to expose all of the details of
the JWT, such as issuer, audience, expiration, etc. to rest of the
application.  Route handlers should only be concerned with the
information about the user, rather than the metadata about how the user
was authenticated.
This commit is contained in:
2025-04-08 20:29:47 -05:00
parent 3d2772cfc8
commit a50dca7fae
4 changed files with 97 additions and 48 deletions

View File

@@ -78,7 +78,9 @@ async fn test_login() {
assert_eq!(location, "/");
let cookie = res.cookies().get("auth.token").unwrap();
debug!("Cookie: {:?}", cookie);
let claims = ctx.decode_jwt(cookie.value()).unwrap();
debug!("Claims: {:?}", claims);
assert!(!claims.sub.is_empty());
// Check to ensure the cookie contains a valid token
let user = ctx.decode_jwt(cookie.value()).unwrap();
debug!("User: {:?}", user);
assert!(!user.id().is_empty());
}