Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/graph/authentication/mutations/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def login_user!(credentials)
user = User.find_by(email: credentials[:email])
raise StandardError unless user&.authenticate(credentials[:password])

token = JwtHelper.encode_token({ user_id: user.id })
token = JwtHelper.encode_token({ email: user.email, user_id: user.id })
{ user: user, token: token }
end
end
Expand Down
5 changes: 3 additions & 2 deletions app/helpers/jwt_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

module JwtHelper
class << self
SECRET = ENV['RJPA_SECRET']
SECRET = ENV['JWT_SECRET']

def encode_token(payload)
payload[:exp] = Time.now.to_i + ENV['JWT_EXPIRATION'].to_i
JWT.encode(payload, SECRET)
end

Expand All @@ -22,7 +23,7 @@ def logged_in_user(token)

def decoded_token(token)
JWT.decode(token, SECRET, true, algorithm: ENV['JWT_ALGORITHM'])
rescue StandardError => e
rescue JWT::ExpiredSignature, StandardError => e
GraphQL::ExecutionError.new(e.message)
nil
end
Expand Down
5 changes: 3 additions & 2 deletions config/local_env.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
RJPA_SECRET: 'RJPA_SECRET'
JWT_ALGORITHM: 'HS256'
JWT_ALGORITHM: 'HS256'
JWT_EXPIRATION: '3600'
JWT_SECRET: 'RJPA_SECRET'