Skip to content

Commit 7d719e6

Browse files
committed
adding WIP prisma example app, it need testing
1 parent 70540a1 commit 7d719e6

File tree

16 files changed

+4542
-13
lines changed

16 files changed

+4542
-13
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ const config: NextAuthPubkeyConfig = {
7979
secret: process.env.NEXTAUTH_SECRET,
8080
storage: {
8181
async set({ k1, session }) {
82-
// save lnurl auth session data based on k1 id
82+
// save pubkey auth session data based on k1 id
8383
},
8484
async get({ k1 }) {
85-
// lookup and return lnurl auth session data based on k1 id
85+
// lookup and return pubkey auth session data based on k1 id
8686
},
8787
async update({ k1, session }) {
88-
// update lnurl auth session data based on k1 id
88+
// update pubkey auth session data based on k1 id
8989
},
9090
async delete({ k1 }) {
91-
// delete lnurl auth session data based on k1 id
91+
// delete pubkey auth session data based on k1 id
9292
},
9393
},
9494
generateQr,
@@ -185,7 +185,7 @@ const config: NextAuthPubkeyConfig = {
185185
* data for later use.
186186
*/
187187
async set({ k1, session }) {
188-
// save lnurl auth session data based on k1 id
188+
// save pubkey auth session 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 lnurl auth session data based on k1 id
199+
// lookup and return pubkey auth session data based on k1 id
200200
},
201201

202202
/**
@@ -210,7 +210,7 @@ const config: NextAuthPubkeyConfig = {
210210
* an existing session is not already stored under the k1.
211211
*/
212212
async update({ k1, session }) {
213-
// update lnurl auth session data based on k1 id
213+
// update pubkey auth session 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 lnurl auth session data based on k1 id
224+
// delete pubkey auth session data based on k1 id
225225
},
226226
},
227227

examples/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ The [examples/plain-js/](https://github.com/jowo-io/next-auth-pubkey/tree/main/e
1010

1111
### KV
1212

13-
The [examples/kv/](https://github.com/jowo-io/next-auth-pubkey/tree/main/examples/kv) example demonstrates how to configure `next-auth-pubkey` using Vercel [KV](https://vercel.com/docs/storage/vercel-kv) for storage of the lnurl auth data.
13+
The [examples/kv/](https://github.com/jowo-io/next-auth-pubkey/tree/main/examples/kv) example demonstrates how to configure `next-auth-pubkey` using Vercel [KV](https://vercel.com/docs/storage/vercel-kv) for storage of the pubkey auth data.
1414

1515
### Prisma
1616

17-
> COMING SOON
17+
The [examples/prisma/](https://github.com/jowo-io/next-auth-pubkey/tree/main/examples/prisma) example demonstrates how to configure `next-auth-pubkey` using the [Prisma ORM](https://www.prisma.io/) and MySql for storage of the pubkey auth data.
1818

1919
### Drizzle
2020

21-
The [examples/drizzle/](https://github.com/jowo-io/next-auth-pubkey/tree/main/examples/drizzle) example demonstrates how to configure `next-auth-pubkey` using the [Drizzle ORM](https://github.com/drizzle-team/drizzle-orm) and MySql for storage of the lnurl auth data.
21+
The [examples/drizzle/](https://github.com/jowo-io/next-auth-pubkey/tree/main/examples/drizzle) example demonstrates how to configure `next-auth-pubkey` using the [Drizzle ORM](https://github.com/drizzle-team/drizzle-orm) and MySql for storage of the pubkey auth data.
2222

2323
### MongoDB
2424

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 lnurl 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 auth session data.
44

55
## Getting Started
66

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 lnurl auth session data.
3+
This example uses the Vercel [KV](https://vercel.com/docs/storage/vercel-kv) (Redis) for storage of pubkey auth session data.
44

55
## Getting Started
66

examples/prisma/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts
36+
37+
# env
38+
.env

examples/prisma/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## About
2+
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.
4+
5+
## Getting Started
6+
7+
#### Building `next-auth-pubkey`
8+
9+
Before you can run this example locally, you must clone and build `next-auth-pubkey`.
10+
11+
Essentially all that's required is running `npm i` and `npm run build` from the directory root.
12+
13+
#### Create env vars
14+
15+
Along side the `.env.example` file in this example app, create a `.env` file with the same contents and fill all of the variables with real values.
16+
17+
#### Running this examples
18+
19+
Run `npm i` to install dependencies.
20+
21+
Run `npm run dev` to launch the dev server and visit `localhost:3000` to view the app.

examples/prisma/env.mjs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { z } from "zod";
2+
3+
/** @type {Record<keyof z.infer<typeof server> | keyof z.infer<typeof client>, string | undefined>} */
4+
const processEnv = {
5+
DATABASE_URL: process.env.DATABASE_URL,
6+
7+
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
8+
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
9+
10+
NODE_ENV: process.env.NODE_ENV,
11+
};
12+
13+
const client = z.object({
14+
NEXTAUTH_URL: z.string().min(1),
15+
16+
NODE_ENV: z.enum(["development", "test", "production"]),
17+
});
18+
19+
const server = z.object({
20+
DATABASE_URL: z.string(),
21+
22+
NEXTAUTH_URL: z.string().min(1),
23+
NEXTAUTH_SECRET: z.string(),
24+
25+
NODE_ENV: z.enum(["development", "test", "production"]),
26+
});
27+
28+
// Don't touch the part below
29+
// --------------------------
30+
31+
const merged = server.merge(client);
32+
33+
/** @typedef {z.input<typeof merged>} MergedInput */
34+
/** @typedef {z.infer<typeof merged>} MergedOutput */
35+
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */
36+
37+
let env = /** @type {MergedOutput} */ (process.env);
38+
39+
if (!!process.env.SKIP_ENV_VALIDATION == false) {
40+
const isServer = typeof window === "undefined";
41+
42+
const parsed = /** @type {MergedSafeParseReturn} */ (
43+
isServer
44+
? merged.safeParse(processEnv) // on server we can validate all env vars
45+
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
46+
);
47+
48+
if (parsed.success === false) {
49+
console.error(
50+
"❌ Invalid environment variables:",
51+
parsed.error.flatten().fieldErrors
52+
);
53+
throw new Error("Invalid environment variables");
54+
}
55+
56+
env = new Proxy(parsed.data, {
57+
get(target, prop) {
58+
if (typeof prop !== "string") return undefined;
59+
// Throw a descriptive error if a server-side env var is accessed on the client
60+
// Otherwise it would just be returning `undefined` and be annoying to debug
61+
if (!isServer && !prop.startsWith("NEXT_PUBLIC_") && prop !== "NODE_ENV")
62+
throw new Error(
63+
process.env.NODE_ENV === "production"
64+
? "❌ Attempted to access a server-side environment variable on the client"
65+
: `❌ Attempted to access server-side environment variable '${prop}' on the client`
66+
);
67+
return target[/** @type {keyof typeof target} */ (prop)];
68+
},
69+
});
70+
}
71+
72+
export { env };

examples/prisma/next.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var path = require("path");
2+
3+
/** @type {import('next').NextConfig} */
4+
const nextConfig = {
5+
webpack: (config) => {
6+
// These alias configurations are not required. They are only needed for development in the mono repo's example/ folder
7+
config.resolve.alias["next"] = path.resolve("./node_modules/next");
8+
config.resolve.alias["next-auth"] = path.resolve(
9+
"./node_modules/next-auth"
10+
);
11+
config.resolve.alias["react"] = path.resolve("./node_modules/react");
12+
return config;
13+
},
14+
};
15+
16+
module.exports = nextConfig;

0 commit comments

Comments
 (0)