After getting a LoginResponse from the Lemmy API, it returns an auth JWT token.

I’m trying to figure out how I can get that users person_id or username so I can make a GetPersonDetails request for the currently logged in user.

Any ideas on how to do this?

  • plisken@lemmy.fmhy.ml
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 year ago

    I haven’t tried, but usually a JWT contains some sort of user ID

    https://github.com/LemmyNet/lemmy/blob/main/crates/utils/src/claims.rs#L9-L15

    pub struct Claims {
      /// local_user_id, standard claim by RFC 7519.
      pub sub: i32,
      pub iss: String,
      /// Time when this token was issued as UNIX-timestamp in seconds
      pub iat: i64,
    }
    

    For instance if I decode my current JWT, the payload contains:

    {
      "sub": 123,
      "iss": "lemmy.fmhy.ml",
      "iat": 1686668459
    }
    

    sub is the local_user_id

    If you’re unfamiliar with JWT, check https://jwt.io for a primer and a helpful tool to decode.

    • Charlie FishOPA
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      I was looking at that, but it didn’t seem to be the person_id of my user.

      It looks like maybe local_user_id is different than person_id?