Skip to content

Commit

Permalink
add ExpressJwtRequestUnrequired to the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jfromaniello committed Apr 28, 2022
1 parent d6f09de commit 3890f53
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,27 @@ app.get(
);
```

If you use `credentialsRequired: false` then use `ExpressJwtRequestUnrequired`. This type defines `req.auth` as optional, example:

```typescript
import { expressjwt, ExpressJwtRequest } from "express-jwt";

app.get(
"/protected",
expressjwt({
secret: "shhhhhhared-secret",
algorithms: ["HS256"],
credentialsRequired: false,
}),
function (req: ExpressJwtRequestUnrequired, res: express.Response) {
if (!req.auth?.admin) {
return res.sendStatus(401);
}
res.sendStatus(200);
}
);
```

## Migration from v6

1. The middleware function is now available as a named import rather than a default one: import { expressjwt } from 'express-jwt'
Expand Down

0 comments on commit 3890f53

Please sign in to comment.