Files
astuto/app/controllers/api_keys_controller.rb

19 lines
449 B
Ruby
Raw Normal View History

2024-11-08 16:40:53 +01:00
class ApiKeysController < ApplicationController
before_action :authenticate_user!
def create
current_user.api_key&.destroy # Destroy existing API key
@api_key = ApiKey.new(user: current_user)
authorize @api_key
if @api_key.save
render json: { api_key: @api_key.token }, status: :created
else
render json: {
errors: @api_key.errors.full_messages
}, status: :unprocessable_entity
end
end
end