Read Token signing key from environment
This commit is contained in:
@@ -16,6 +16,10 @@ pub struct Claims {
|
||||
pub exp: i64,
|
||||
}
|
||||
|
||||
pub fn secret_key() -> String {
|
||||
dotenv::var("SECRET_KEY").unwrap()
|
||||
}
|
||||
|
||||
impl FromStr for Claims {
|
||||
type Err = jsonwebtoken::errors::Error;
|
||||
|
||||
@@ -24,7 +28,7 @@ impl FromStr for Claims {
|
||||
|
||||
match decode::<Claims>(
|
||||
&token,
|
||||
&DecodingKey::from_secret("secret_token".as_ref()),
|
||||
&DecodingKey::from_secret(secret_key().as_bytes()),
|
||||
&Validation::new(Algorithm::HS256),
|
||||
) {
|
||||
Ok(data) => Ok(data.claims),
|
||||
|
||||
Reference in New Issue
Block a user