fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
http::StatusCode,
|
http::{StatusCode, HeaderMap},
|
||||||
Json,
|
Json,
|
||||||
};
|
};
|
||||||
use axum_login::AuthSession;
|
use axum_login::AuthSession;
|
||||||
@@ -70,6 +70,7 @@ fn model_to_response(model: InviteLinkModel, base_url: &str) -> InviteLinkRespon
|
|||||||
)]
|
)]
|
||||||
pub async fn create_invite_link(
|
pub async fn create_invite_link(
|
||||||
auth_session: AuthSession<AuthBackend>,
|
auth_session: AuthSession<AuthBackend>,
|
||||||
|
headers: HeaderMap,
|
||||||
State(db): State<DatabaseConnection>,
|
State(db): State<DatabaseConnection>,
|
||||||
Json(payload): Json<CreateInviteLinkRequest>,
|
Json(payload): Json<CreateInviteLinkRequest>,
|
||||||
) -> Result<Json<InviteLinkResponse>, StatusCode> {
|
) -> Result<Json<InviteLinkResponse>, StatusCode> {
|
||||||
@@ -84,7 +85,11 @@ pub async fn create_invite_link(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
|
|
||||||
let base_url = std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string());
|
let base_url = headers
|
||||||
|
.get("origin")
|
||||||
|
.and_then(|v| v.to_str().ok())
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.unwrap_or_else(|| std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string()));
|
||||||
Ok(Json(model_to_response(invite, &base_url)))
|
Ok(Json(model_to_response(invite, &base_url)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +106,7 @@ pub async fn create_invite_link(
|
|||||||
)]
|
)]
|
||||||
pub async fn get_my_invite_links(
|
pub async fn get_my_invite_links(
|
||||||
auth_session: AuthSession<AuthBackend>,
|
auth_session: AuthSession<AuthBackend>,
|
||||||
|
headers: HeaderMap,
|
||||||
State(db): State<DatabaseConnection>,
|
State(db): State<DatabaseConnection>,
|
||||||
) -> Result<Json<Vec<InviteLinkResponse>>, StatusCode> {
|
) -> Result<Json<Vec<InviteLinkResponse>>, StatusCode> {
|
||||||
let user = auth_session.user.ok_or(StatusCode::UNAUTHORIZED)?;
|
let user = auth_session.user.ok_or(StatusCode::UNAUTHORIZED)?;
|
||||||
@@ -110,7 +116,11 @@ pub async fn get_my_invite_links(
|
|||||||
.await
|
.await
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
|
|
||||||
let base_url = std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string());
|
let base_url = headers
|
||||||
|
.get("origin")
|
||||||
|
.and_then(|v| v.to_str().ok())
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.unwrap_or_else(|| std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string()));
|
||||||
let responses: Vec<InviteLinkResponse> = invites
|
let responses: Vec<InviteLinkResponse> = invites
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|i| model_to_response(i, &base_url))
|
.map(|i| model_to_response(i, &base_url))
|
||||||
|
|||||||
Reference in New Issue
Block a user