mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 11:47:56 +01:00
19 lines
449 B
Ruby
19 lines
449 B
Ruby
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 |