"fix: add family to authorized_families on create and OAuth login

This commit is contained in:
arrelin
2026-01-17 10:59:19 +03:00
parent 3e0e6ff456
commit baccf0429b
2 changed files with 27 additions and 0 deletions

View File

@@ -221,6 +221,7 @@ pub struct CreateMyFamilyResponse {
)] )]
pub async fn create_my_family( pub async fn create_my_family(
auth_session: AuthSession<AuthBackend>, auth_session: AuthSession<AuthBackend>,
session: Session,
State(db): State<DatabaseConnection>, State(db): State<DatabaseConnection>,
Json(payload): Json<CreateMyFamilyRequest>, Json(payload): Json<CreateMyFamilyRequest>,
) -> Result<Json<CreateMyFamilyResponse>, StatusCode> { ) -> Result<Json<CreateMyFamilyResponse>, StatusCode> {
@@ -247,6 +248,17 @@ pub async fn create_my_family(
.await .await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let mut authorized_families: Vec<i32> = session
.get("authorized_families")
.await
.unwrap_or(None)
.unwrap_or_default();
authorized_families.push(family.id);
session
.insert("authorized_families", authorized_families)
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(Json(CreateMyFamilyResponse { Ok(Json(CreateMyFamilyResponse {
family_id: family.id, family_id: family.id,
user_id: current_user.id, user_id: current_user.id,

View File

@@ -119,6 +119,21 @@ pub async fn google_callback(
.await .await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
if let Some(family_id) = user.family_id {
let mut authorized_families: Vec<i32> = session
.get("authorized_families")
.await
.unwrap_or(None)
.unwrap_or_default();
if !authorized_families.contains(&family_id) {
authorized_families.push(family_id);
session
.insert("authorized_families", authorized_families)
.await
.ok();
}
}
let redirect_url = frontend_url.unwrap_or_else(|| "http://localhost:3000".to_string()); let redirect_url = frontend_url.unwrap_or_else(|| "http://localhost:3000".to_string());
Ok(Redirect::temporary(&redirect_url)) Ok(Redirect::temporary(&redirect_url))