Skip to content

Commit ab9801c

Browse files
Refactor LicenseValidator to simplify validation logic and remove unnecessary checks
1 parent 5d6514f commit ab9801c

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

react_on_rails_pro/lib/react_on_rails_pro/license_validator.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "jwt"
4-
require "pathname"
54

65
module ReactOnRailsPro
76
class LicenseValidator
@@ -33,16 +32,13 @@ def license_data
3332

3433
def validate_license
3534
license = load_and_decode_license
36-
# If no license found, load_license_string already handled the error
37-
return false unless license
3835

3936
# Check that exp field exists
4037
unless license["exp"]
4138
@validation_error = "License is missing required expiration field. " \
4239
"Your license may be from an older version. " \
4340
"Get a FREE evaluation license at https://shakacode.com/react-on-rails-pro"
4441
handle_invalid_license(@validation_error)
45-
return false
4642
end
4743

4844
# Check expiry
@@ -51,32 +47,25 @@ def validate_license
5147
"Get a FREE evaluation license (3 months) at https://shakacode.com/react-on-rails-pro " \
5248
"or upgrade to a paid license for production use."
5349
handle_invalid_license(@validation_error)
54-
return false
5550
end
5651

5752
# Log license type if present (for analytics)
5853
log_license_info(license)
5954

6055
true
61-
rescue ReactOnRailsPro::Error
62-
# Re-raise errors from handle_invalid_license
63-
raise
6456
rescue JWT::DecodeError => e
6557
@validation_error = "Invalid license signature: #{e.message}. " \
6658
"Your license file may be corrupted. " \
6759
"Get a FREE evaluation license at https://shakacode.com/react-on-rails-pro"
6860
handle_invalid_license(@validation_error)
69-
false
7061
rescue StandardError => e
7162
@validation_error = "License validation error: #{e.message}. " \
7263
"Get a FREE evaluation license at https://shakacode.com/react-on-rails-pro"
7364
handle_invalid_license(@validation_error)
74-
false
7565
end
7666

7767
def load_and_decode_license
7868
license_string = load_license_string
79-
return nil unless license_string
8069

8170
JWT.decode(
8271
license_string,
@@ -88,6 +77,7 @@ def load_and_decode_license
8877
algorithm: "RS256",
8978
# Disable automatic expiration verification so we can handle it manually with custom logic
9079
verify_expiration: false
80+
# JWT.decode returns an array [data, header]; we use `.first` to get the data (payload).
9181
).first
9282
end
9383

@@ -104,7 +94,6 @@ def load_license_string
10494
"or create config/react_on_rails_pro_license.key file. " \
10595
"Get a FREE evaluation license at https://shakacode.com/react-on-rails-pro"
10696
handle_invalid_license(@validation_error)
107-
nil
10897
end
10998

11099
def public_key
@@ -118,8 +107,6 @@ def handle_invalid_license(message)
118107
end
119108

120109
def log_license_info(license)
121-
return unless license
122-
123110
plan = license["plan"]
124111
issued_by = license["issued_by"]
125112

0 commit comments

Comments
 (0)