add code to require authentication for 2 controllers functions (2 different syntax)

This commit is contained in:
Douze Bé 2024-10-21 17:01:55 +02:00
parent ee1a27bb8d
commit d1102dcf8b
2 changed files with 8 additions and 0 deletions

View file

@ -10,6 +10,7 @@ use crate::{
models::_entities::servers::{ActiveModel, Column, Entity, Model},
views,
};
use crate::models::users;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Params {
@ -31,9 +32,14 @@ async fn load_item(ctx: &AppContext, id: i32) -> Result<Model> {
#[debug_handler]
pub async fn list(
auth: auth::JWT,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {
// we only want to make sure user exists, so we name the variable
// with a `_` in front to remove the warning about unused variable
let _current_user = users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await?;
let item = Entity::find()
.order_by(Column::Id, Order::Desc)
.all(&ctx.db)

View file

@ -10,6 +10,7 @@ use crate::{
models::_entities::services::{ActiveModel, Column, Entity, Model},
views,
};
use crate::models::users;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Params {
@ -33,6 +34,7 @@ async fn load_item(ctx: &AppContext, id: i32) -> Result<Model> {
#[debug_handler]
pub async fn list(
_user: auth::ApiToken<users::Model>,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<Response> {