Skip to content

Commit 5ffa7ad

Browse files
Merge pull request #3033 from kryptonpust/patch-1
docs(passport.md): explains express authInfo populate procedure
2 parents 06042fe + c3266cd commit 5ffa7ad

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

content/recipes/passport.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ The `validate()` method deserves some discussion. For the jwt-strategy, Passport
628628

629629
As a result of all this, our response to the `validate()` callback is trivial: we simply return an object containing the `userId` and `username` properties. Recall again that Passport will build a `user` object based on the return value of our `validate()` method, and attach it as a property on the `Request` object.
630630

631+
Additionally, you can return an array, where the first value is used to create a `user` object and the second value is used to create an `authInfo` object.
632+
631633
It's also worth pointing out that this approach leaves us room ('hooks' as it were) to inject other business logic into the process. For example, we could do a database lookup in our `validate()` method to extract more information about the user, resulting in a more enriched `user` object being available in our `Request`. This is also the place we may decide to do further token validation, such as looking up the `userId` in a list of revoked tokens, enabling us to perform token revocation. The model we've implemented here in our sample code is a fast, "stateless JWT" model, where each API call is immediately authorized based on the presence of a valid JWT, and a small bit of information about the requester (its `userId` and `username`) is available in our Request pipeline.
632634

633635
Add the new `JwtStrategy` as a provider in the `AuthModule`:

0 commit comments

Comments
 (0)