Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit efe92ed

Browse files
author
Ian Walter
committed
Adding usage to README
1 parent 3b4240e commit efe92ed

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,38 @@ flexible than other CSRF modules by being split into two separate middleware:
1010
one that handles the CSRF token generation and one that handles the CSRF token
1111
validation.
1212

13+
## Installation
14+
15+
```console
16+
yarn add @ianwalter/express-csrf
17+
```
18+
19+
## Usage
20+
21+
Use the `csrfGeneration` middleware before you intend to use the
22+
`req.generateCsrfToken` method to generate a CSRF token:
23+
24+
```js
25+
const { csrfGeneration } = require('@ianwalter/express-csrf')
26+
27+
app.use(csrfGeneration)
28+
```
29+
30+
Use the `csrfValidation` middleware before any endpoints you want to protect
31+
from CSRF attacks:
32+
33+
```js
34+
const { csrfValidation } = require('@ianwalter/express-csrf')
35+
36+
// Doesn't need to be proected:
37+
app.post('/login', session.create)
38+
39+
app.use(csrfValidation)
40+
41+
// Protected:
42+
app.post('/order', orders.create)
43+
```
44+
1345
## License
1446

1547
Apache 2.0 with Commons Clause - See [LICENSE][licenseUrl]

0 commit comments

Comments
 (0)