-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding WIP prisma example app, it need testing
- Loading branch information
Showing
16 changed files
with
4,542 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.