Class: Pusher::PushNotifications::UseCases::GenerateToken

Inherits:
Object
  • Object
show all
Defined in:
lib/pusher/push_notifications/use_cases/generate_token.rb

Defined Under Namespace

Classes: GenerateTokenError

Class Method Summary collapse

Class Method Details

.generate_token(user:) ⇒ Object

Creates a signed JWT for a user id.

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pusher/push_notifications/use_cases/generate_token.rb', line 10

def self.generate_token(user:)
  raise GenerateTokenError, 'User Id cannot be empty.' if user.empty?

  if user.length > UserId::MAX_USER_ID_LENGTH
    raise GenerateTokenError, 'User id length too long ' \
    "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
  end

  jwt_token = PushNotifications::Token.new

  { 'token' => jwt_token.generate(user) }
end