From 65b79edfd41853ceaaf05b83262d62edd76ce50a Mon Sep 17 00:00:00 2001 From: Abel Lavieri Date: Fri, 15 Dec 2023 12:27:47 -0400 Subject: [PATCH] Add admin authentication --- app/controllers/api/games_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/games_controller.rb b/app/controllers/api/games_controller.rb index 458f2c4..811574a 100644 --- a/app/controllers/api/games_controller.rb +++ b/app/controllers/api/games_controller.rb @@ -13,8 +13,9 @@ def show def create @game = Game.new(game_params) + user = User.find(params[:user_id]) - if current_user.is_admin && @game.save + if user.is_admin && @game.save render json: @game, status: :created else render json: @game.errors, status: :unprocessable_entity @@ -22,7 +23,7 @@ def create end def destroy - if current_user.is_admin && @game.destroy + if @game.destroy head :no_content else render json: @game.errors, status: :unprocessable_entity