Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I_Helmet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 62
I_Helmet
Commits
dd2525eb
Commit
dd2525eb
authored
Apr 27, 2022
by
Balasuriya D.A.M.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JSON Web Token(JWT)
parent
372c0ddf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
2 deletions
+18
-2
IT18021080/Telemedicine-Chat-App/backend/config/generateToken.js
...080/Telemedicine-Chat-App/backend/config/generateToken.js
+14
-0
IT18021080/Telemedicine-Chat-App/backend/controllers/userControllers.js
...emedicine-Chat-App/backend/controllers/userControllers.js
+3
-1
IT18021080/Telemedicine-Chat-App/backend/server.js
IT18021080/Telemedicine-Chat-App/backend/server.js
+1
-1
No files found.
IT18021080/Telemedicine-Chat-App/backend/config/generateToken.js
0 → 100644
View file @
dd2525eb
const
jwt
=
require
(
"
jsonwebtoken
"
);
//create generatetoken function
const
generateToken
=
(
id
)
=>
{
//add jwt secret from .env
return
jwt
.
sign
({
id
},
process
.
env
.
JWT_SECRET
,
{
//can change the count of days as i want (secret days)
expiresIn
:
"
30d
"
,
});
};
module
.
exports
=
generateToken
;
//JWT use for pass user data to backend through JWT
\ No newline at end of file
IT18021080/Telemedicine-Chat-App/backend/controllers/userControllers.js
View file @
dd2525eb
const
asyncHandler
=
require
(
"
express-async-handler
"
);
const
User
=
require
(
"
../models/userModel
"
);
const
generateToken
=
require
(
"
../config/generateToken
"
);
const
registerUser
=
asyncHandler
(
async
(
req
,
res
)
=>
{
const
{
name
,
email
,
password
,
pic
}
=
req
.
body
;
...
...
@@ -23,13 +24,14 @@ const registerUser = asyncHandler(async (req, res) => {
password
,
pic
,
});
//after register..also want send JWT token
if
(
user
)
{
res
.
status
(
201
).
json
({
_id
:
user
.
_id
,
name
:
user
.
name
,
email
:
user
.
email
,
pic
:
user
.
pic
,
token
:
generateToken
(
user
.
_id
),
});
}
else
{
res
.
status
(
400
);
...
...
IT18021080/Telemedicine-Chat-App/backend/server.js
View file @
dd2525eb
...
...
@@ -12,7 +12,7 @@ dotenv.config();
connectDB
();
const
app
=
express
();
app
.
use
(
express
.
json
());
//to accept JSON data
app
.
get
(
"
/
"
,
(
req
,
res
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment