Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
Triz_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sdy
2020-04-26 17:57:55 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cbc9e2213fc99fa07613c89e0e97227154c08add
cbc9e221
1 parent
96f0ebab
create passport.js
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
back/src/passport.js
back/src/passport.js
0 → 100644
View file @
cbc9e22
import
passport
from
"passport"
;
import
{
Strategy
,
ExtractJwt
}
from
"passport-jwt"
;
import
{
prisma
}
from
"./utils"
;
const
JWTOptions
=
{
jwtFromRequest
:
ExtractJwt
.
fromAuthHeaderAsBearerToken
(),
secretOrKey
:
process
.
env
.
JWT_SECRET
,
};
const
verifyUser
=
async
(
payload
,
done
)
=>
{
try
{
const
user
=
await
prisma
.
user
.
findOne
({
where
:
{
id
:
payload
.
id
,
},
});
if
(
user
!==
null
)
{
return
done
(
null
,
user
);
}
else
{
return
done
(
null
,
false
);
}
}
catch
(
error
)
{
return
done
(
null
,
false
);
}
};
export
const
authenticateJWT
=
(
req
,
res
,
next
)
=>
{
passport
.
authenticate
(
"jwt"
,
{
session
:
false
},
(
error
,
user
)
=>
{
if
(
user
)
{
req
.
user
=
user
;
}
next
();
})(
req
,
res
,
next
);
};
passport
.
use
(
new
Strategy
(
JWTOptions
,
verifyUser
));
passport
.
initialize
();
Please
register
or
login
to post a comment