@eloritzkovitz/server-essentials
Preparing search index...
auth/authorization
authenticate
Function authenticate
authenticate
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
:
void
Express middleware to check if the user is authenticated via JWT.
Expects the JWT in the 'Authorization' header as 'Bearer
'.
Attaches the user object ({ id, role }) to req.user if valid.
Responds with 401 if token is missing or invalid.
Responds with 500 if TOKEN_SECRET is not set.
Usage: app.use(authenticate);
Parameters
req
:
Request
res
:
Response
next
:
NextFunction
Returns
void
Settings
Member Visibility
Protected
Inherited
External
Theme
OS
Light
Dark
@eloritzkovitz/server-essentials
Loading...
Express middleware to check if the user is authenticated via JWT.
Usage: app.use(authenticate);