Skip to content

Commit

Permalink
adding WIP prisma example app, it need testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jowo-io committed Oct 20, 2024
1 parent 70540a1 commit 7d719e6
Show file tree
Hide file tree
Showing 16 changed files with 4,542 additions and 13 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ const config: NextAuthPubkeyConfig = {
secret: process.env.NEXTAUTH_SECRET,
storage: {
async set({ k1, session }) {
// save lnurl auth session data based on k1 id
// save pubkey auth session data based on k1 id
},
async get({ k1 }) {
// lookup and return lnurl auth session data based on k1 id
// lookup and return pubkey auth session data based on k1 id
},
async update({ k1, session }) {
// update lnurl auth session data based on k1 id
// update pubkey auth session data based on k1 id
},
async delete({ k1 }) {
// delete lnurl auth session data based on k1 id
// delete pubkey auth session data based on k1 id
},
},
generateQr,
Expand Down Expand Up @@ -185,7 +185,7 @@ const config: NextAuthPubkeyConfig = {
* data for later use.
*/
async set({ k1, session }) {
// save lnurl auth session data based on k1 id
// save pubkey auth session data based on k1 id
},

/**
Expand All @@ -196,7 +196,7 @@ const config: NextAuthPubkeyConfig = {
* and return data previously stored under it.
*/
async get({ k1 }) {
// lookup and return lnurl auth session data based on k1 id
// lookup and return pubkey auth session data based on k1 id
},

/**
Expand All @@ -210,7 +210,7 @@ const config: NextAuthPubkeyConfig = {
* an existing session is not already stored under the k1.
*/
async update({ k1, session }) {
// update lnurl auth session data based on k1 id
// update pubkey auth session data based on k1 id
},

/**
Expand All @@ -221,7 +221,7 @@ const config: NextAuthPubkeyConfig = {
* delete data previously saved data.
*/
async delete({ k1 }) {
// delete lnurl auth session data based on k1 id
// delete pubkey auth session data based on k1 id
},
},

Expand Down
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ The [examples/plain-js/](https://github.com/jowo-io/next-auth-pubkey/tree/main/e

### KV

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.
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.

### Prisma

> COMING SOON
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.

### Drizzle

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.
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.

### MongoDB

Expand Down
2 changes: 1 addition & 1 deletion examples/drizzle/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## About

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.
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.

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion examples/kv/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## About

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

## Getting Started

Expand Down
38 changes: 38 additions & 0 deletions examples/prisma/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# env
.env
21 changes: 21 additions & 0 deletions examples/prisma/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## About

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.

## Getting Started

#### Building `next-auth-pubkey`

Before you can run this example locally, you must clone and build `next-auth-pubkey`.

Essentially all that's required is running `npm i` and `npm run build` from the directory root.

#### Create env vars

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.

#### Running this examples

Run `npm i` to install dependencies.

Run `npm run dev` to launch the dev server and visit `localhost:3000` to view the app.
72 changes: 72 additions & 0 deletions examples/prisma/env.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { z } from "zod";

/** @type {Record<keyof z.infer<typeof server> | keyof z.infer<typeof client>, string | undefined>} */
const processEnv = {
DATABASE_URL: process.env.DATABASE_URL,

NEXTAUTH_URL: process.env.NEXTAUTH_URL,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,

NODE_ENV: process.env.NODE_ENV,
};

const client = z.object({
NEXTAUTH_URL: z.string().min(1),

NODE_ENV: z.enum(["development", "test", "production"]),
});

const server = z.object({
DATABASE_URL: z.string(),

NEXTAUTH_URL: z.string().min(1),
NEXTAUTH_SECRET: z.string(),

NODE_ENV: z.enum(["development", "test", "production"]),
});

// Don't touch the part below
// --------------------------

const merged = server.merge(client);

/** @typedef {z.input<typeof merged>} MergedInput */
/** @typedef {z.infer<typeof merged>} MergedOutput */
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */

let env = /** @type {MergedOutput} */ (process.env);

if (!!process.env.SKIP_ENV_VALIDATION == false) {
const isServer = typeof window === "undefined";

const parsed = /** @type {MergedSafeParseReturn} */ (
isServer
? merged.safeParse(processEnv) // on server we can validate all env vars
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
);

if (parsed.success === false) {
console.error(
"❌ Invalid environment variables:",
parsed.error.flatten().fieldErrors
);
throw new Error("Invalid environment variables");
}

env = new Proxy(parsed.data, {
get(target, prop) {
if (typeof prop !== "string") return undefined;
// Throw a descriptive error if a server-side env var is accessed on the client
// Otherwise it would just be returning `undefined` and be annoying to debug
if (!isServer && !prop.startsWith("NEXT_PUBLIC_") && prop !== "NODE_ENV")
throw new Error(
process.env.NODE_ENV === "production"
? "❌ Attempted to access a server-side environment variable on the client"
: `❌ Attempted to access server-side environment variable '${prop}' on the client`
);
return target[/** @type {keyof typeof target} */ (prop)];
},
});
}

export { env };
16 changes: 16 additions & 0 deletions examples/prisma/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var path = require("path");

/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
// These alias configurations are not required. They are only needed for development in the mono repo's example/ folder
config.resolve.alias["next"] = path.resolve("./node_modules/next");
config.resolve.alias["next-auth"] = path.resolve(
"./node_modules/next-auth"
);
config.resolve.alias["react"] = path.resolve("./node_modules/react");
return config;
},
};

module.exports = nextConfig;
Loading

0 comments on commit 7d719e6

Please sign in to comment.