Перенести все админские эндпоинты на порт 8445 и добавить отдельную авторизацию для админов. Часть 2. Final #3
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
-module(handler_user_me).
|
||||
-include("records.hrl").
|
||||
|
||||
-export([init/2]).
|
||||
|
||||
init(Req, Opts) ->
|
||||
handle(Req, Opts).
|
||||
init(Req, Opts) -> handle(Req, Opts).
|
||||
|
||||
handle(Req, _Opts) ->
|
||||
case cowboy_req:method(Req) of
|
||||
@@ -14,10 +12,10 @@ handle(Req, _Opts) ->
|
||||
case core_user:get_by_id(UserId) of
|
||||
{ok, User} ->
|
||||
Response = #{
|
||||
id => User#user.id,
|
||||
email => User#user.email,
|
||||
role => User#user.role,
|
||||
status => User#user.status,
|
||||
id => User#user.id,
|
||||
email => User#user.email,
|
||||
role => User#user.role,
|
||||
status => User#user.status,
|
||||
created_at => User#user.created_at,
|
||||
updated_at => User#user.updated_at
|
||||
},
|
||||
@@ -36,8 +34,7 @@ authenticate(Req) ->
|
||||
case cowboy_req:parse_header(<<"authorization">>, Req) of
|
||||
{bearer, Token} ->
|
||||
case logic_auth:verify_jwt(Token) of
|
||||
{ok, Claims} ->
|
||||
UserId = maps:get(<<"user_id">>, Claims),
|
||||
{ok, UserId, _Role} -> % ← теперь возвращается {ok, UserId, Role}
|
||||
{ok, UserId, Req};
|
||||
{error, expired} ->
|
||||
{error, 401, <<"Token expired">>, Req};
|
||||
|
||||
Reference in New Issue
Block a user