Skip to content

Commit d963bb5

Browse files
committed
renaming the next-auth-pubkey "session" argument so that it's not confused with the "next-auth" session object
1 parent 0465612 commit d963bb5

File tree

29 files changed

+82
-101
lines changed

29 files changed

+82
-101
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ const config: NextAuthPubkeyConfig = {
7878
baseUrl: process.env.NEXTAUTH_URL,
7979
secret: process.env.NEXTAUTH_SECRET,
8080
storage: {
81-
async set({ k1, session }) {
82-
// save pubkey auth session data based on k1 id
81+
async set({ k1, data }) {
82+
// save pubkey data based on k1 id
8383
},
8484
async get({ k1 }) {
85-
// lookup and return pubkey auth session data based on k1 id
85+
// lookup and return pubkey data based on k1 id
8686
},
87-
async update({ k1, session }) {
88-
// update pubkey auth session data based on k1 id
87+
async update({ k1, data }) {
88+
// update pubkey data based on k1 id
8989
},
9090
async delete({ k1 }) {
91-
// delete pubkey auth session data based on k1 id
91+
// delete pubkey data based on k1 id
9292
},
9393
},
9494
generateQr,
@@ -167,7 +167,7 @@ const config: NextAuthPubkeyConfig = {
167167
* @param {object} storage
168168
*
169169
* pubkey auth flows require that a callback be triggered
170-
* part of the authentication flow. So, we require session storage to
170+
* part of the authentication flow. So, storage is required to
171171
* persist some data and ensure it's available when the callback is triggered.
172172
* Data can be stored in a medium of your choice.
173173
*
@@ -184,8 +184,8 @@ const config: NextAuthPubkeyConfig = {
184184
* The k1 is a unique key that's used to store the
185185
* data for later use.
186186
*/
187-
async set({ k1, session }) {
188-
// save pubkey auth session data based on k1 id
187+
async set({ k1, data }) {
188+
// save pubkey data based on k1 id
189189
},
190190

191191
/**
@@ -196,7 +196,7 @@ const config: NextAuthPubkeyConfig = {
196196
* and return data previously stored under it.
197197
*/
198198
async get({ k1 }) {
199-
// lookup and return pubkey auth session data based on k1 id
199+
// lookup and return pubkey data based on k1 id
200200
},
201201

202202
/**
@@ -207,10 +207,10 @@ const config: NextAuthPubkeyConfig = {
207207
* update data previously stored under it.
208208
*
209209
* @note the storage.update method should throw an error if
210-
* an existing session is not already stored under the k1.
210+
* an existing data is not already stored under the k1.
211211
*/
212-
async update({ k1, session }) {
213-
// update pubkey auth session data based on k1 id
212+
async update({ k1, data }) {
213+
// update pubkey data based on k1 id
214214
},
215215

216216
/**
@@ -221,7 +221,7 @@ const config: NextAuthPubkeyConfig = {
221221
* delete data previously saved data.
222222
*/
223223
async delete({ k1 }) {
224-
// delete pubkey auth session data based on k1 id
224+
// delete pubkey data based on k1 id
225225
},
226226
},
227227

@@ -493,7 +493,7 @@ const config: NextAuthPubkeyConfig = {
493493

494494
# Storage
495495

496-
pubkey auth flows require that a callback be triggered on success as part of the authentication flow. For this reason, it may be that the device scanning the QR (e.g. a mobile) is not the same device that's trying to authenticate (e.g. a desktop). So, we require session storage to persist some data and make it available across devices and ensure it's available when the callback is triggered.
496+
pubkey auth flows require that a callback be triggered on success as part of the authentication flow. For this reason, it may be that the device scanning the QR (e.g. a mobile) is not the same device that's trying to authenticate (e.g. a desktop). So, we require data storage to persist some data and make it available across devices and ensure it's available when the callback is triggered.
497497

498498
Data can be stored in a medium of your choice. For example: a database, a document store, or a session store. Here's an example using [Vercel KV](https://vercel.com/docs/storage/vercel-kv):
499499

@@ -503,15 +503,15 @@ import { kv } from "@vercel/kv";
503503
const config: NextAuthPubkeyConfig = {
504504
// ...
505505
storage: {
506-
async set({ k1, session }) {
507-
await kv.set(`k1:${k1}`, session);
506+
async set({ k1, data }) {
507+
await kv.set(`k1:${k1}`, data);
508508
},
509509
async get({ k1 }) {
510510
return await kv.get(`k1:${k1}`);
511511
},
512-
async update({ k1, session }) {
512+
async update({ k1, data }) {
513513
const old = (await kv.get(`k1:${k1}`)) || {};
514-
await kv.set(`k1:${k1}`, { ...old, ...session });
514+
await kv.set(`k1:${k1}`, { ...old, ...data });
515515
},
516516
async delete({ k1 }) {
517517
await kv.del(`k1:${k1}`);
@@ -529,7 +529,7 @@ Once you have configured the storage functions you can launch your dev server an
529529
http://localhost:3000/api/pubkey/diagnostics
530530
```
531531

532-
On the diagnostic page you can optionally pass in your own custom session values via query param:
532+
On the diagnostic page you can optionally pass in your own custom values via query param:
533533

534534
```
535535
http://localhost:3000/api/pubkey/diagnostics?k1=custom-k1&state=custom-state&pubkey=custom-pubkey&sig=custom-sig

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Below is a TODO list for further development of `next-auth-pubkey`.
1616
- test all user configuration options
1717
- tidy up READMEs
1818
- add BTC address to contributors section of readme
19-
- add suggestion: cleaning up old and unused pubkey session data that was created but never reached success state.
19+
- add suggestion: cleaning up old and unused pubkey data that was created but never reached success state.
2020

2121
### Release
2222

examples/app-router/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/app-router/utils/nextauth.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ import storage from "node-persist"; // ⚠️ WARNING using node-persist is not
1010
await storage.init();
1111

1212
const config: NextAuthPubkeyConfig = {
13-
// required
1413
baseUrl: env.NEXTAUTH_URL,
1514
secret: env.NEXTAUTH_SECRET,
1615
storage: {
17-
async set({ k1, session }) {
18-
await storage.setItem(`k1:${k1}`, session);
16+
async set({ k1, data }) {
17+
await storage.setItem(`k1:${k1}`, data);
1918
},
2019
async get({ k1 }) {
2120
return await storage.getItem(`k1:${k1}`);
2221
},
23-
async update({ k1, session }) {
22+
async update({ k1, data }) {
2423
const old = await storage.getItem(`k1:${k1}`);
2524
if (!old) throw new Error(`Could not find k1:${k1}`);
26-
await storage.updateItem(`k1:${k1}`, { ...old, ...session });
25+
await storage.updateItem(`k1:${k1}`, { ...old, ...data });
2726
},
2827
async delete({ k1 }) {
2928
await storage.removeItem(`k1:${k1}`);

examples/drizzle/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## About
22

3-
This example uses the [Drizzle ORM](https://github.com/drizzle-team/drizzle-orm) to connect to a MySql database which is used for storage of pubkey auth session data.
3+
This example uses the [Drizzle ORM](https://github.com/drizzle-team/drizzle-orm) to connect to a MySql database which is used for storage of pubkey data.
44

55
## Getting Started
66

examples/drizzle/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/drizzle/pages/api/pubkey/[...pubkey].ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import db from "@/utils/db";
88
import { env } from "@/env.mjs";
99

1010
const config: NextAuthPubkeyConfig = {
11-
// required
1211
baseUrl: env.NEXTAUTH_URL,
1312
secret: env.NEXTAUTH_SECRET,
1413
storage: {
15-
async set({ k1, session }) {
16-
await db.insert(pubkeyTable).values(session);
14+
async set({ data }) {
15+
await db.insert(pubkeyTable).values(data);
1716
},
1817
async get({ k1 }) {
1918
const results: PubKey[] = await db
@@ -23,10 +22,10 @@ const config: NextAuthPubkeyConfig = {
2322

2423
return results[0];
2524
},
26-
async update({ k1, session }) {
25+
async update({ k1, data }) {
2726
const results = await db
2827
.update(pubkeyTable)
29-
.set(session)
28+
.set(data)
3029
.where(eq(pubkeyTable.k1, k1));
3130
if (!results[0].affectedRows) throw new Error(`Could not find k1:${k1}`);
3231
},

examples/kv/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## About
22

3-
This example uses the Vercel [KV](https://vercel.com/docs/storage/vercel-kv) (Redis) for storage of pubkey auth session data.
3+
This example uses the Vercel [KV](https://vercel.com/docs/storage/vercel-kv) (Redis) for storage of pubkey data.
44

55
## Getting Started
66

examples/kv/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/kv/pages/api/pubkey/[...pubkey].ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ import { kv } from "@vercel/kv";
66
import { env } from "@/env.mjs";
77

88
const config: NextAuthPubkeyConfig = {
9-
// required
109
baseUrl: env.NEXTAUTH_URL,
1110
secret: env.NEXTAUTH_SECRET,
1211
storage: {
13-
async set({ k1, session }) {
14-
await kv.set(`k1:${k1}`, session);
12+
async set({ k1, data }) {
13+
await kv.set(`k1:${k1}`, data);
1514
},
1615
async get({ k1 }) {
1716
return await kv.get(`k1:${k1}`);
1817
},
19-
async update({ k1, session }) {
18+
async update({ k1, data }) {
2019
const old = await kv.get(`k1:${k1}`);
2120
if (!old) throw new Error(`Could not find k1:${k1}`);
22-
await kv.set(`k1:${k1}`, { ...old, ...session });
21+
await kv.set(`k1:${k1}`, { ...old, ...data });
2322
},
2423
async delete({ k1 }) {
2524
await kv.del(`k1:${k1}`);

examples/plain-js/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/plain-js/pages/api/pubkey/[...pubkey].js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ import storage from "node-persist"; // ⚠️ WARNING using node-persist is not
66
await storage.init();
77

88
const config = {
9-
// required
109
baseUrl: process.env.NEXTAUTH_URL,
1110
secret: process.env.NEXTAUTH_SECRET,
1211
storage: {
13-
async set({ k1, session }) {
14-
await storage.setItem(`k1:${k1}`, session);
12+
async set({ k1, data }) {
13+
await storage.setItem(`k1:${k1}`, data);
1514
},
1615
async get({ k1 }) {
1716
return await storage.getItem(`k1:${k1}`);
1817
},
19-
async update({ k1, session }) {
18+
async update({ k1, data }) {
2019
const old = await storage.getItem(`k1:${k1}`);
2120
if (!old) throw new Error(`Could not find k1:${k1}`);
22-
await storage.updateItem(`k1:${k1}`, { ...old, ...session });
21+
await storage.updateItem(`k1:${k1}`, { ...old, ...data });
2322
},
2423
async delete({ k1 }) {
2524
await storage.removeItem(`k1:${k1}`);

examples/prisma/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## About
22

3-
This example uses the [Prisma ORM](https://www.prisma.io/) to connect to a MySql database which is used for storage of pubkey auth session data.
3+
This example uses the [Prisma ORM](https://www.prisma.io/) to connect to a MySql database which is used for storage of pubkey data.
44

55
## Getting Started
66

examples/prisma/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prisma/pages/api/pubkey/[...pubkey].ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,19 @@ const config: NextAuthPubkeyConfig = {
1111
baseUrl: env.NEXTAUTH_URL,
1212
secret: env.NEXTAUTH_SECRET,
1313
storage: {
14-
async set({ session }) {
15-
await prisma.pubkey.create({
16-
data: session,
17-
});
14+
async set({ data }) {
15+
await prisma.pubkey.create({ data });
1816
},
1917
async get({ k1 }) {
20-
const results = await prisma.pubkey.findUnique({
21-
where: { k1 },
22-
});
18+
const results = await prisma.pubkey.findUnique({ where: { k1 } });
2319
if (!results) throw new Error(`Could not find k1:${k1}`);
2420
return results;
2521
},
26-
async update({ k1, session }) {
27-
await prisma.pubkey.update({
28-
where: { k1 },
29-
data: session,
30-
});
22+
async update({ k1, data }) {
23+
await prisma.pubkey.update({ where: { k1 }, data });
3124
},
3225
async delete({ k1 }) {
33-
await prisma.pubkey.delete({
34-
where: { k1 },
35-
});
26+
await prisma.pubkey.delete({ where: { k1 } });
3627
},
3728
},
3829
generateQr,

examples/ui-app-router/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ui-app-router/utils/nextauth.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,25 @@ import storage from "node-persist"; // ⚠️ WARNING using node-persist is not
1010
await storage.init();
1111

1212
const config: NextAuthPubkeyConfig = {
13-
// required
1413
baseUrl: env.NEXTAUTH_URL,
1514
secret: env.NEXTAUTH_SECRET,
1615
storage: {
17-
async set({ k1, session }) {
18-
await storage.setItem(`k1:${k1}`, session);
16+
async set({ k1, data }) {
17+
await storage.setItem(`k1:${k1}`, data);
1918
},
2019
async get({ k1 }) {
2120
return await storage.getItem(`k1:${k1}`);
2221
},
23-
async update({ k1, session }) {
22+
async update({ k1, data }) {
2423
const old = await storage.getItem(`k1:${k1}`);
2524
if (!old) throw new Error(`Could not find k1:${k1}`);
26-
await storage.updateItem(`k1:${k1}`, { ...old, ...session });
25+
await storage.updateItem(`k1:${k1}`, { ...old, ...data });
2726
},
2827
async delete({ k1 }) {
2928
await storage.removeItem(`k1:${k1}`);
3029
},
3130
},
3231
generateQr,
33-
34-
// optional
3532
pages: {
3633
lightningSignIn: "/lightning-signin",
3734
nostrSignIn: "/nostr-signin",

examples/ui-pages-router/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)