Module: UserAuth::Web::Helpers

Defined in:
lib/user_auth/web/helpers.rb

Instance Method Summary collapse

Instance Method Details

#build_jwt(data) ⇒ Object



27
28
29
30
# File 'lib/user_auth/web/helpers.rb', line 27

def build_jwt(data)
  exp = Time.now.to_i + UserAuth.configuration.jwt_exp
  AuthToken.new.create(data.merge(exp: exp))
end

#current_userObject



6
7
8
# File 'lib/user_auth/web/helpers.rb', line 6

def current_user
  @current_user ||= UserAuth::Models::User.with_pk!(warden.user.user_id)
end

#deliver_email(options) ⇒ Object



10
11
12
# File 'lib/user_auth/web/helpers.rb', line 10

def deliver_email(options)
  UserAuth.configuration.deliver_mail.call(options)
end

#json(data) ⇒ Object



14
15
16
17
# File 'lib/user_auth/web/helpers.rb', line 14

def json(data)
  content_type(:json)
  JSON.dump(data)
end

#json_user_token(user) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/user_auth/web/helpers.rb', line 19

def json_user_token(user)
  json(
    token_type: "Bearer",
    token: build_jwt(user.to_json),
    refresh_token: user.refresh_token!
  )
end