1 use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation};
2 use lemmy_db_schema::source::user::User_;
3 use lemmy_utils::settings::Settings;
4 use serde::{Deserialize, Serialize};
8 #[derive(Debug, Serialize, Deserialize)]
15 pub fn decode(jwt: &str) -> Result<TokenData<Claims>, jsonwebtoken::errors::Error> {
18 ..Validation::default()
22 &DecodingKey::from_secret(Settings::get().jwt_secret.as_ref()),
27 pub fn jwt(user: User_, hostname: String) -> Result<Jwt, jsonwebtoken::errors::Error> {
28 let my_claims = Claims {
35 &EncodingKey::from_secret(Settings::get().jwt_secret.as_ref()),