Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use modern Rust dependencies #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Change AUTH_SECRET back to "your_secret_key"
ggrossman committed Jul 10, 2024
commit f330af82cb6581b32814d92e53930d543606dd18
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -32,7 +32,8 @@ struct SessionJWT {
password: String,
}

static AUTH_SECRET: &str = "ef3b28c9951edd3151d9abb14e8e2909b5fc535c986e7cb588b32b0d2082a9b9";
static AUTH_SECRET: &str = "your_secret_key";
static JWT_EXPIRATION_SECS: u64 = 3600;

async fn get_data_string(result: mongodb::error::Result<Document>) -> Result<web::Json<Document>, String> {
match result {
@@ -138,9 +139,8 @@ async fn login(info: web::Json<UserLogin>) -> impl Responder {
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_secs();
println!("{:?}", since_the_epoch);

let claims = SessionJWT { iat: since_the_epoch, exp: since_the_epoch+3600, email, password };
let claims = SessionJWT { iat: since_the_epoch, exp: since_the_epoch+JWT_EXPIRATION_SECS, email, password };
let token = encode(&Header::default(), &claims, &EncodingKey::from_secret(AUTH_SECRET.as_ref())).unwrap();

HttpResponse::Ok().body(token)