Implemented user authentication.
This commit is contained in:
+11
-5
@@ -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(()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user