Implemented user authentication.

This commit is contained in:
2023-09-22 21:26:13 +02:00
parent 0bac17f2eb
commit 17f628739f
23 changed files with 704 additions and 326 deletions
+11 -5
View File
@@ -1,11 +1,14 @@
use crate::backend::data::Company;
use leptos::*;
use crate::backend::data::{ApiResponse, Company};
#[server(GetCompany, "/api", "Url", "get_company")]
pub async fn get_company() -> Result<Company, ServerFnError> {
pub async fn get_company() -> Result<ApiResponse<Company>, ServerFnError> {
use crate::backend::AppData;
use actix_web::web::Data;
use leptos_actix::extract;
use crate::perm_check;
perm_check!(is_logged_in);
let pool = extract(|data: Data<AppData>| async move { data.db_pool().clone() }).await?;
@@ -13,14 +16,17 @@ pub async fn get_company() -> Result<Company, ServerFnError> {
.fetch_one(&pool)
.await?;
Ok(cmp)
Ok(ApiResponse::Data(cmp))
}
#[server(UpdateCompany, "/api", "Url", "update_company")]
pub async fn update_company(company: Company) -> Result<(), ServerFnError> {
pub async fn update_company(company: Company) -> Result<ApiResponse<()>, ServerFnError> {
use crate::backend::AppData;
use actix_web::web::Data;
use leptos_actix::extract;
use crate::perm_check;
perm_check!(is_admin);
let pool = extract(|data: Data<AppData>| async move { data.db_pool().clone() }).await?;
@@ -36,5 +42,5 @@ pub async fn update_company(company: Company) -> Result<(), ServerFnError> {
.execute(&pool)
.await?;
Ok(())
Ok(ApiResponse::Data(()))
}