7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/api/partner/v1/staff_token_controller.rb', line 7
def verify_token
token = params[:token]
return render json: { success: false, message: 'Token is required' }, status: :bad_request if token.blank?
begin
auth_token = Knock::AuthToken.new(token: token)
staff = Staff.find(auth_token.payload['sub'])
if staff&.persisted?
render json: {
success: true,
message: 'Valid token',
}.merge(Api::Partner::StaffSerializer.new(staff).as_json)
else
render json: { success: false, message: 'Invalid token' }, status: :unauthorized
end
rescue JWT::DecodeError, ActiveRecord::RecordNotFound
render json: { success: false, message: 'Invalid token' }, status: :unauthorized
end
end
|