Skip to content

Commit 0bef4a8

Browse files
authored
docs(readme), test: generateCsrf no longer require await (#164)
1 parent 267aba1 commit 0bef4a8

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fastify.route({
4747
method: 'GET',
4848
path: '/',
4949
handler: async (req, reply) => {
50-
const token = await reply.generateCsrf()
50+
const token = reply.generateCsrf()
5151
return { token }
5252
}
5353
})
@@ -77,7 +77,7 @@ fastify.route({
7777
method: 'GET',
7878
path: '/',
7979
handler: async (req, reply) => {
80-
const token = await reply.generateCsrf()
80+
const token = reply.generateCsrf()
8181
return { token }
8282
}
8383
})
@@ -107,7 +107,7 @@ fastify.route({
107107
method: 'GET',
108108
path: '/',
109109
handler: async (req, reply) => {
110-
const token = await reply.generateCsrf()
110+
const token = reply.generateCsrf()
111111
return { token }
112112
}
113113
})
@@ -153,7 +153,7 @@ Apart from these safeguards, it is extremely important to [use HTTPS for your we
153153
Generates a secret (if it is not already present) and returns a promise that resolves to the associated secret.
154154

155155
```js
156-
const token = await reply.generateCsrf()
156+
const token = reply.generateCsrf()
157157
```
158158

159159
You can also pass the [cookie serialization](https://github.com/fastify/fastify-cookie) options to the function.

examples/example.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fastify.route({
2424
method: 'GET',
2525
url: '/',
2626
handler: async (req, reply) => {
27-
const token = await reply.generateCsrf()
27+
const token = reply.generateCsrf()
2828
reply.type('text/html')
2929

3030
return `

test/basic.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('Cookies', t => {
3232
const fastify = await load()
3333

3434
fastify.get('/', async (req, reply) => {
35-
const token = await reply.generateCsrf()
35+
const token = reply.generateCsrf()
3636
return { token }
3737
})
3838

@@ -179,7 +179,7 @@ function runTest (t, load, tkn, hook = 'onRequest') {
179179
const fastify = await load()
180180

181181
fastify.get('/', async (req, reply) => {
182-
const token = await reply.generateCsrf()
182+
const token = reply.generateCsrf()
183183
return { token }
184184
})
185185

@@ -274,7 +274,7 @@ function runCookieOpts (t, load) {
274274
const fastify = await load()
275275

276276
fastify.get('/', async (req, reply) => {
277-
const token = await reply.generateCsrf({ path: '/hello' })
277+
const token = reply.generateCsrf({ path: '/hello' })
278278
return { token }
279279
})
280280

test/user-info.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('Cookies with User-Info', async t => {
2828
}
2929

3030
fastify.post('/login', async (req, reply) => {
31-
const token = await reply.generateCsrf({ userInfo: userInfoDB[req.body.username] })
31+
const token = reply.generateCsrf({ userInfo: userInfoDB[req.body.username] })
3232
return { token }
3333
})
3434

@@ -84,7 +84,7 @@ test('Session with User-Info', async t => {
8484

8585
fastify.post('/login', async (req, reply) => {
8686
req.session.username = req.body.username
87-
const token = await reply.generateCsrf({ userInfo: req.body.username })
87+
const token = reply.generateCsrf({ userInfo: req.body.username })
8888
return { token }
8989
})
9090

@@ -136,7 +136,7 @@ test('SecureSession with User-Info', async t => {
136136

137137
fastify.post('/login', async (req, reply) => {
138138
req.session.set('username', req.body.username)
139-
const token = await reply.generateCsrf({ userInfo: req.body.username })
139+
const token = reply.generateCsrf({ userInfo: req.body.username })
140140
return { token }
141141
})
142142

0 commit comments

Comments
 (0)