feat: finish adding device name to login, register, and refresh endpoints

This commit is contained in:
Twig 2025-07-15 02:42:53 +02:00
parent 7872d2ec24
commit fc061738fa
No known key found for this signature in database
7 changed files with 21 additions and 29 deletions

View file

@ -7,7 +7,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use crate::{
error::Error, schema::{
access_tokens::{self, dsl},
refresh_tokens::{self, device_name, dsl as rdsl},
refresh_tokens::{self, dsl as rdsl},
}, utils::{generate_token, new_refresh_token_cookie}, Data
};
@ -50,7 +50,7 @@ pub async fn res(req: HttpRequest, data: web::Data<Data>) -> Result<HttpResponse
}
let current_time = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() as i64;
let existing_device_name: String;
let mut device_name: String = String::new();
if lifetime > 1987200 {
let new_refresh_token = generate_token::<32>()?;
@ -65,9 +65,9 @@ pub async fn res(req: HttpRequest, data: web::Data<Data>) -> Result<HttpResponse
.get_result::<String>(&mut conn)
.await
{
Ok(device_name) => {
Ok(existing_device_name) => {
refresh_token = new_refresh_token;
existing_device_name = device_name.to_string();
device_name = existing_device_name;
}
Err(error) => {
error!("{error}");
@ -88,7 +88,7 @@ pub async fn res(req: HttpRequest, data: web::Data<Data>) -> Result<HttpResponse
return Ok(HttpResponse::Ok()
.cookie(new_refresh_token_cookie(&data.config, refresh_token))
.json(Response { access_token, existing_device_name }));
.json(Response { access_token, device_name }));
}
refresh_token_cookie.make_removal();