Skip to content

Commit

Permalink
get JWT token from a header
Browse files Browse the repository at this point in the history
bump version
  • Loading branch information
damianham committed May 15, 2019
1 parent 4c96a5f commit da0a998
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/src/pipes/authenticate_jwt.cr.lqd
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ end
class AuthenticateJWT < Amber::Pipe::Base
PUBLIC_PATHS = ["/", "/signin", "/session", "/signup", "/registration", "/me"]

# add the names of the app modules
# add the regular expressions of paths that have public access
# e.g. add paths to view instances of certain models or all paths
# within the support tree
REGEX_PATHS = [
%r(/categories(/\d+)?$),
%r(/products(/\d+)?$),
%r(/comments(/\d+)?$),
%r(/some_model_name(/\d+)?$),
%r(/support/.*$/),
]

def call(context)
if context.params["token"]?
payload, header = JWT.decode(context.params["token"], Amber.settings.secret_key_base, "HS256")
token = context.params["token"]? || context.request.headers["x-jwt-token"]?
if token
payload, header = JWT.decode(token, Amber.settings.secret_key_base, "HS256")
user = User.find_by(email: payload["email"].to_s) unless payload["email"]?.nil?
elsif user_id = context.session["user_id"]?
user = User.find user_id
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: amber_react_sidebar
version: 1.0.3
version: 1.0.4

authors:
- Damian Hamill <damianham@gmail.com>
Expand Down

0 comments on commit da0a998

Please sign in to comment.