feat: persist current workspace in user sessions
This commit is contained in:
@@ -5,7 +5,9 @@ use serde_json::json;
|
||||
use crate::{
|
||||
auth::{AuthenticatedSession, cleared_session_cookie, extract_session_token, session_cookie},
|
||||
error::ApiError,
|
||||
service::{ChangePasswordPayload, LoginPayload, UpdateProfilePayload},
|
||||
service::{
|
||||
ChangePasswordPayload, LoginPayload, UpdateCurrentWorkspacePayload, UpdateProfilePayload,
|
||||
},
|
||||
state::AppState,
|
||||
};
|
||||
|
||||
@@ -55,9 +57,11 @@ pub async fn get_session(
|
||||
pub async fn get_profile(
|
||||
Extension(session): Extension<AuthenticatedSession>,
|
||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||
Ok(Json(
|
||||
json!({ "user": session.user, "memberships": session.memberships }),
|
||||
))
|
||||
Ok(Json(json!({
|
||||
"user": session.user,
|
||||
"memberships": session.memberships,
|
||||
"current_workspace_id": session.current_workspace_id
|
||||
})))
|
||||
}
|
||||
|
||||
pub async fn update_profile(
|
||||
@@ -67,7 +71,27 @@ pub async fn update_profile(
|
||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||
let updated = state
|
||||
.service
|
||||
.update_profile(&session.user.id, payload)
|
||||
.update_profile(
|
||||
&session.user.id,
|
||||
session.current_workspace_id.as_ref(),
|
||||
payload,
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(json!(updated)))
|
||||
}
|
||||
|
||||
pub async fn update_current_workspace(
|
||||
State(state): State<AppState>,
|
||||
Extension(session): Extension<AuthenticatedSession>,
|
||||
Json(payload): Json<UpdateCurrentWorkspacePayload>,
|
||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||
let updated = state
|
||||
.service
|
||||
.set_current_workspace(
|
||||
&session.session_id,
|
||||
&session.user.id,
|
||||
&payload.workspace_id.as_str().into(),
|
||||
)
|
||||
.await?;
|
||||
Ok(Json(json!(updated)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user