Nest.js passport package
The @nestjs/passport
package is an extensible package that allows you to use any strategy from passport into Nest.js. As seen in the previous section, it is possible to implement the authentication manually, but if you want to
do it in a quicker way and have the strategy wrapped, then use the good package.
In this section, you will see the usage of the package using jwt
as shown in the previous section. To use it you have to install the following package:
npm install --save @nestjs/passport passport passport-jwt jsonwebtoken
To use the package you will have the possibility to use the exact same AuthenticationService
that you have implemented in the previous section, but remember to follow the next code sample.
@
Injectable
()
export
class
AuthenticationService
{
constructor
(
private
readonly
userService
:UserService
)
{
}
createToken
(
string
,
ttl?
:number
)
{
const
expiresIn
=
ttl
||
60
*
60
;
const
secretOrKey
=
'secret...