mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-20 00:35:22 +00:00
wrap key rotation in a transaction (#626)
This commit is contained in:
parent
241d8c8ebe
commit
bce3b1ae0d
1 changed files with 5 additions and 3 deletions
|
|
@ -37,11 +37,13 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def rotate_api_key
|
||||
@user.api_keys.destroy_all
|
||||
@user.api_keys.transaction do
|
||||
@user.api_keys.destroy_all
|
||||
|
||||
new_api_key = @user.api_keys.create!(name: "Hackatime key")
|
||||
new_api_key = @user.api_keys.create!(name: "Hackatime key")
|
||||
|
||||
render json: { token: new_api_key.token }, status: :ok
|
||||
render json: { token: new_api_key.token }, status: :ok
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.error("error rotate #{e.class.name} #{e.message}")
|
||||
render json: { error: "cant rotate" }, status: :unprocessable_entity
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue