Uncomment and update decode_token()

This commit is contained in:
bitfl0wer 2024-08-22 21:52:29 +02:00
parent cfccae8060
commit e9b3de2342
No known key found for this signature in database
GPG Key ID: 8D90CA11485CD14D
1 changed files with 13 additions and 5 deletions

View File

@ -3,7 +3,10 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::utils::Snowflake;
use jsonwebtoken::{encode, EncodingKey, Header};
use jsonwebtoken::errors::Error;
use jsonwebtoken::{
decode, encode, Algorithm, DecodingKey, EncodingKey, Header, TokenData, Validation,
};
use serde::{Deserialize, Serialize};
pub fn generate_token(id: &Snowflake, email: String, jwt_key: &str) -> String {
@ -42,8 +45,13 @@ pub fn build_token(claims: &Claims, jwt_key: &str) -> Result<String, jsonwebtoke
)
}
/*pub fn decode_token(token: &str) -> Result<TokenData<Claims>, Error> {
pub fn decode_token(token: &str, jwt_secret: &str) -> Result<TokenData<Claims>, Error> {
let mut validation = Validation::new(Algorithm::HS256);
validation.sub = Some("quartzauth".to_string());
decode(token, &DecodingKey::from_secret(JWT_SECRET), &validation)
}*/
//TODO: What is this?
//validation.sub = Some("quartzauth".to_string());
decode(
token,
&DecodingKey::from_secret(jwt_secret.as_bytes()),
&validation,
)
}