修改token过期时间

This commit is contained in:
李运家 2024-05-23 08:34:44 +08:00
parent 0840048161
commit 94aaedf986
2 changed files with 6 additions and 5 deletions

View File

@ -43,8 +43,8 @@ pub struct Logger {
#[derive(Clone, Debug, Deserialize)]
pub struct Jwt {
pub secret: String,
pub expires: usize,
pub refresh_expires: usize,
pub expires: i64,
pub refresh_expires: i64,
}
#[macro_export]

View File

@ -1,3 +1,4 @@
use chrono::{TimeDelta, Utc};
use serde::{Deserialize, Serialize};
use crate::config;
@ -5,13 +6,13 @@ use crate::config;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Claims {
sub: i64, // 用户ID
exp: usize, // Token过期时间戳
exp: i64, // Token过期时间戳
}
pub fn generate_token(sub: i64) -> String {
let claim = Claims {
sub,
exp: config!().jwt.expires,
exp: (Utc::now() + TimeDelta::try_seconds(config!().jwt.expires).unwrap()).timestamp(),
};
generate(claim)
}
@ -19,7 +20,7 @@ pub fn generate_token(sub: i64) -> String {
pub fn generate_refresh_token(sub: i64) -> String {
let claim = Claims {
sub,
exp: config!().jwt.refresh_expires,
exp: (Utc::now() + TimeDelta::try_seconds(config!().jwt.refresh_expires).unwrap()).timestamp(),
};
generate(claim)
}