Toggle navigation
Toggle navigation
This project
Loading...
Sign in
황선혁
/
weather_chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Eric Whale
2022-05-24 16:58:33 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ee5f84a69bf605904a50b514f4bbf53d75e5e17e
ee5f84a6
1 parent
07c49a4f
Add jwt token to signin, signup
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
actions/userActions.js
config/jwt.js
actions/userActions.js
View file @
ee5f84a
const
jwt
=
require
(
"jsonwebtoken"
);
const
bcrypt
=
require
(
"bcryptjs"
);
// handles "exception" inside of async express routes
const
asyncHandler
=
require
(
"express-async-handler"
);
const
User
=
require
(
"../models/userModel"
);
const
jwtGenerator
=
require
(
"../config/jwt"
);
// @desc Signup new user
// @route POST /api/users
...
...
@@ -39,7 +39,7 @@ const signupUser = asyncHandler(async (req, res) => {
_id
:
user
.
id
,
username
:
user
.
username
,
email
:
user
.
email
,
// TODO: Add token!
token
:
jwtGenerator
(
user
.
_id
),
});
}
else
{
res
.
status
(
400
);
...
...
@@ -61,7 +61,7 @@ const loginUser = asyncHandler(async (req, res) => {
_id
:
userInDB
.
id
,
username
:
userInDB
.
username
,
email
:
userInDB
.
email
,
// TODO: Add Token!
token
:
jwtGenerator
(
userInDB
.
_id
),
});
}
else
{
res
.
status
(
400
);
...
...
@@ -72,7 +72,10 @@ const loginUser = asyncHandler(async (req, res) => {
// @desc Get user(only self)
// @route GET /api/users/self
// @access Private
const
getSelf
=
asyncHandler
(
async
(
req
,
res
)
=>
{});
const
getSelf
=
asyncHandler
(
async
(
req
,
res
)
=>
{
// Not figured out
res
.
status
(
200
).
json
(
req
.
user
);
});
module
.
exports
=
{
signupUser
,
...
...
config/jwt.js
0 → 100644
View file @
ee5f84a
const
jwt
=
require
(
"jsonwebtoken"
);
const
jwtGenerator
=
(
id
)
=>
{
// https://github.com/auth0/node-jsonwebtoken
const
token
=
jwt
.
sign
({
id
},
JWT_SECRET
,
{
expiresIn
:
"2 days"
});
return
token
;
};
module
.
exports
=
{
jwtGenerator
};
Please
register
or
login
to post a comment