-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8a46f8
commit ad06a94
Showing
21 changed files
with
807 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const path = require('path') | ||
|
||
/** @type {import("eslint").Linter.Config} */ | ||
const config = { | ||
overrides: [ | ||
{ | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended-requiring-type-checking', | ||
], | ||
files: ['*.ts', '*.tsx'], | ||
parserOptions: { | ||
project: path.join(__dirname, 'tsconfig.json'), | ||
}, | ||
}, | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: path.join(__dirname, 'tsconfig.json'), | ||
}, | ||
plugins: ['@typescript-eslint', 'simple-import-sort', 'unused-imports'], | ||
extends: ['next/core-web-vitals', 'plugin:@typescript-eslint/recommended'], | ||
rules: { | ||
'@typescript-eslint/consistent-type-imports': [ | ||
'warn', | ||
{ | ||
prefer: 'type-imports', | ||
fixStyle: 'inline-type-imports', | ||
}, | ||
], | ||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], | ||
|
||
'simple-import-sort/imports': 'error', | ||
'simple-import-sort/exports': 'warn', | ||
'unused-imports/no-unused-imports': 'error', | ||
}, | ||
} | ||
|
||
module.exports = config |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -26,7 +26,8 @@ yarn-error.log* | |
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
.env | ||
.env | ||
|
||
# vercel | ||
.vercel | ||
|
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,83 @@ | ||
import { z } from 'zod' | ||
|
||
/** | ||
* Specify server-side environment variables schema here. | ||
*/ | ||
const server = z.object({ | ||
DATABASE_URL: z.string().url(), | ||
NODE_ENV: z.enum(['development', 'test', 'production']), | ||
CLERK_SECRET_KEY: z.string().min(1), | ||
// DISCORD_CLIENT_ID: z.string().min(1), | ||
// DISCORD_CLIENT_SECRET: z.string().min(1), | ||
// GITHUB_ID: z.string().min(1), | ||
// GITHUB_SECRET: z.string().min(1), | ||
// GOOGLE_CLIENT_ID: z.string().min(1), | ||
// GOOGLE_CLIENT_SECRET: z.string().min(1), | ||
}) | ||
|
||
/** | ||
* To expose them to the client, prefix them with `NEXT_PUBLIC_`. | ||
*/ | ||
const client = z.object({ | ||
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1), | ||
}) | ||
|
||
/** | ||
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g. | ||
* middlewares) or client-side so we need to destruct manually. | ||
* | ||
* @type {Record<keyof z.infer<typeof server> | keyof z.infer<typeof client>, string | undefined>} | ||
*/ | ||
const processEnv = { | ||
DATABASE_URL: process.env.DATABASE_URL, | ||
NODE_ENV: process.env.NODE_ENV, | ||
CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY, | ||
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: | ||
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY, | ||
} | ||
|
||
// 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_')) | ||
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
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
/** | ||
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. | ||
* This is especially useful for Docker builds. | ||
*/ | ||
!process.env.SKIP_ENV_VALIDATION && (await import('./env.mjs')) | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
experimental: { | ||
appDir: true, | ||
}, | ||
} | ||
|
||
export default nextConfig |
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,19 @@ | ||
import { createNextApiHandler } from '@trpc/server/adapters/next' | ||
|
||
import { env } from '~/env.mjs' | ||
import { appRouter } from '~/server/api/root' | ||
import { createTRPCContext } from '~/server/api/trpc' | ||
|
||
// export API handler | ||
export default createNextApiHandler({ | ||
router: appRouter, | ||
createContext: createTRPCContext, | ||
onError: | ||
env.NODE_ENV === 'development' | ||
? ({ path, error }) => { | ||
console.error( | ||
`❌ tRPC failed on ${path ?? '<no-path>'}: ${error.message}` | ||
) | ||
} | ||
: undefined, | ||
}) |
Oops, something went wrong.