create-lx2-app 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +151 -0
  2. package/dist/index.js +68 -0
  3. package/package.json +92 -0
  4. package/template/base/README.md +57 -0
  5. package/template/base/_gitignore +41 -0
  6. package/template/base/next-env.d.ts +5 -0
  7. package/template/base/next.config.mjs +12 -0
  8. package/template/base/package.json +20 -0
  9. package/template/base/postcss.config.mjs +5 -0
  10. package/template/base/public/favicon.ico +0 -0
  11. package/template/base/src/env.js +40 -0
  12. package/template/packages/config/eslint.config.mjs +16 -0
  13. package/template/packages/config/payload/with-postgres.ts +39 -0
  14. package/template/packages/config/payload/with-sqlite.ts +42 -0
  15. package/template/packages/config/prettier.config.mjs +23 -0
  16. package/template/packages/config/tsconfig/base.json +42 -0
  17. package/template/packages/config/tsconfig/with-payload.json +43 -0
  18. package/template/packages/prisma/schema/base.prisma +21 -0
  19. package/template/packages/prisma/schema/with-authjs.prisma +86 -0
  20. package/template/packages/prisma/schema/with-better-auth.prisma +85 -0
  21. package/template/packages/src/app/(payload)/admin/[[...segments]]/not-found.tsx +27 -0
  22. package/template/packages/src/app/(payload)/admin/[[...segments]]/page.tsx +27 -0
  23. package/template/packages/src/app/(payload)/admin/importMap.js +1 -0
  24. package/template/packages/src/app/(payload)/api/[...slug]/route.ts +20 -0
  25. package/template/packages/src/app/(payload)/api/graphql/route.ts +8 -0
  26. package/template/packages/src/app/(payload)/api/graphql-playground/route.ts +8 -0
  27. package/template/packages/src/app/(payload)/custom.scss +0 -0
  28. package/template/packages/src/app/(payload)/layout.tsx +35 -0
  29. package/template/packages/src/app/api/auth/[...betterauth]/route.ts +5 -0
  30. package/template/packages/src/app/api/auth/[...nextauth]/route.ts +3 -0
  31. package/template/packages/src/app/globals/base.css +27 -0
  32. package/template/packages/src/app/layout/base.tsx +35 -0
  33. package/template/packages/src/app/page/base.tsx +98 -0
  34. package/template/packages/src/app/page/with-authjs-prisma.tsx +221 -0
  35. package/template/packages/src/app/page/with-authjs.tsx +126 -0
  36. package/template/packages/src/app/page/with-better-auth-prisma.tsx +245 -0
  37. package/template/packages/src/app/page/with-better-auth.tsx +151 -0
  38. package/template/packages/src/app/page/with-payload.tsx +136 -0
  39. package/template/packages/src/app/page/with-prisma.tsx +177 -0
  40. package/template/packages/src/env/with-authjs-db.js +52 -0
  41. package/template/packages/src/env/with-authjs.js +51 -0
  42. package/template/packages/src/env/with-better-auth-db.js +51 -0
  43. package/template/packages/src/env/with-better-auth.js +48 -0
  44. package/template/packages/src/env/with-db.js +44 -0
  45. package/template/packages/src/env/with-payload.js +46 -0
  46. package/template/packages/src/lib/auth/better-auth-client.ts +9 -0
  47. package/template/packages/src/payload/collections/Media.ts +16 -0
  48. package/template/packages/src/payload/collections/Users.ts +13 -0
  49. package/template/packages/src/server/auth/authjs.ts +5 -0
  50. package/template/packages/src/server/auth/config/authjs-with-prisma.ts +30 -0
  51. package/template/packages/src/server/auth/config/authjs.ts +27 -0
  52. package/template/packages/src/server/auth/config/better-auth-with-prisma.ts +21 -0
  53. package/template/packages/src/server/auth/config/better-auth.ts +16 -0
  54. package/template/packages/src/server/db/db-prisma.ts +23 -0
@@ -0,0 +1,44 @@
1
+ import { createEnv } from "@t3-oss/env-nextjs"
2
+ import { z } from "zod"
3
+
4
+ export const env = createEnv({
5
+ /**
6
+ * Specify your server-side environment variables schema here. This way you can ensure the app
7
+ * isn't built with invalid env vars.
8
+ */
9
+ server: {
10
+ DATABASE_URL: z.string().url(),
11
+ NODE_ENV: z
12
+ .enum(["development", "test", "production"])
13
+ .default("development"),
14
+ },
15
+
16
+ /**
17
+ * Specify your client-side environment variables schema here. This way you can ensure the app
18
+ * isn't built with invalid env vars. To expose them to the client, prefix them with
19
+ * `NEXT_PUBLIC_`.
20
+ */
21
+ client: {
22
+ // NEXT_PUBLIC_CLIENTVAR: z.string(),
23
+ },
24
+
25
+ /**
26
+ * You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
27
+ * middlewares) or client-side so we need to destruct manually.
28
+ */
29
+ runtimeEnv: {
30
+ DATABASE_URL: process.env.DATABASE_URL,
31
+ NODE_ENV: process.env.NODE_ENV,
32
+ // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
33
+ },
34
+ /**
35
+ * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
36
+ * useful for Docker builds.
37
+ */
38
+ skipValidation: !!process.env.SKIP_ENV_VALIDATION,
39
+ /**
40
+ * Makes it so that empty strings are treated as undefined. `SOME_VAR: z.string()` and
41
+ * `SOME_VAR=''` will throw an error.
42
+ */
43
+ emptyStringAsUndefined: true,
44
+ })
@@ -0,0 +1,46 @@
1
+ import { createEnv } from "@t3-oss/env-nextjs"
2
+ import { z } from "zod"
3
+
4
+ export const env = createEnv({
5
+ /**
6
+ * Specify your server-side environment variables schema here. This way you can ensure the app
7
+ * isn't built with invalid env vars.
8
+ */
9
+ server: {
10
+ PAYLOAD_SECRET: z.string().min(32),
11
+ DATABASE_URL: z.string().url(),
12
+ NODE_ENV: z
13
+ .enum(["development", "test", "production"])
14
+ .default("development"),
15
+ },
16
+
17
+ /**
18
+ * Specify your client-side environment variables schema here. This way you can ensure the app
19
+ * isn't built with invalid env vars. To expose them to the client, prefix them with
20
+ * `NEXT_PUBLIC_`.
21
+ */
22
+ client: {
23
+ // NEXT_PUBLIC_CLIENTVAR: z.string(),
24
+ },
25
+
26
+ /**
27
+ * You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
28
+ * middlewares) or client-side so we need to destruct manually.
29
+ */
30
+ runtimeEnv: {
31
+ PAYLOAD_SECRET: process.env.PAYLOAD_SECRET,
32
+ DATABASE_URL: process.env.DATABASE_URL,
33
+ NODE_ENV: process.env.NODE_ENV,
34
+ // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
35
+ },
36
+ /**
37
+ * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
38
+ * useful for Docker builds.
39
+ */
40
+ skipValidation: !!process.env.SKIP_ENV_VALIDATION,
41
+ /**
42
+ * Makes it so that empty strings are treated as undefined. `SOME_VAR: z.string()` and
43
+ * `SOME_VAR=''` will throw an error.
44
+ */
45
+ emptyStringAsUndefined: true,
46
+ })
@@ -0,0 +1,9 @@
1
+ import { createAuthClient } from "better-auth/react"
2
+
3
+ import { env } from "@/env"
4
+
5
+ export const authClient = createAuthClient({
6
+ baseURL: env.NEXT_PUBLIC_BETTER_AUTH_URL,
7
+ })
8
+
9
+ export const { signIn, signOut, useSession } = authClient
@@ -0,0 +1,16 @@
1
+ import type { CollectionConfig } from "payload"
2
+
3
+ export const Media: CollectionConfig = {
4
+ slug: "media",
5
+ access: {
6
+ read: () => true,
7
+ },
8
+ fields: [
9
+ {
10
+ name: "alt",
11
+ type: "text",
12
+ required: true,
13
+ },
14
+ ],
15
+ upload: true,
16
+ }
@@ -0,0 +1,13 @@
1
+ import type { CollectionConfig } from "payload"
2
+
3
+ export const Users: CollectionConfig = {
4
+ slug: "users",
5
+ admin: {
6
+ useAsTitle: "email",
7
+ },
8
+ auth: true,
9
+ fields: [
10
+ // Email added by default
11
+ // Add more fields as needed
12
+ ],
13
+ }
@@ -0,0 +1,5 @@
1
+ import NextAuth from "next-auth"
2
+
3
+ import { authConfig } from "@/server/auth/config"
4
+
5
+ export const { handlers, signIn, signOut, auth } = NextAuth(authConfig)
@@ -0,0 +1,30 @@
1
+ import { PrismaAdapter } from "@auth/prisma-adapter"
2
+ import { NextAuthConfig } from "next-auth"
3
+ import Discord from "next-auth/providers/discord"
4
+
5
+ import { env } from "@/env"
6
+ import { db } from "@/server/db"
7
+
8
+ /**
9
+ * This is the Auth.js configuration for the application.
10
+ *
11
+ * @see https://authjs.dev/getting-started/installation
12
+ */
13
+ export const authConfig: NextAuthConfig = {
14
+ adapter: PrismaAdapter(db),
15
+ providers: [
16
+ Discord({
17
+ clientId: env.DISCORD_CLIENT_ID,
18
+ clientSecret: env.DISCORD_CLIENT_SECRET,
19
+ }),
20
+ /**
21
+ * ...add more providers here.
22
+ *
23
+ * Most other providers require a bit more work than the Discord provider. For example, the
24
+ * GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
25
+ * model. Refer to the Auth.js docs for the provider you want to use. Example:
26
+ *
27
+ * @see https://authjs.dev/getting-started/providers/github
28
+ */
29
+ ],
30
+ }
@@ -0,0 +1,27 @@
1
+ import { NextAuthConfig } from "next-auth"
2
+ import Discord from "next-auth/providers/discord"
3
+
4
+ import { env } from "@/env"
5
+
6
+ /**
7
+ * This is the Auth.js configuration for the application.
8
+ *
9
+ * @see https://authjs.dev/getting-started/installation
10
+ */
11
+ export const authConfig: NextAuthConfig = {
12
+ providers: [
13
+ Discord({
14
+ clientId: env.DISCORD_CLIENT_ID,
15
+ clientSecret: env.DISCORD_CLIENT_SECRET,
16
+ }),
17
+ /**
18
+ * ...add more providers here.
19
+ *
20
+ * Most other providers require a bit more work than the Discord provider. For example, the
21
+ * GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
22
+ * model. Refer to the Auth.js docs for the provider you want to use. Example:
23
+ *
24
+ * @see https://authjs.dev/getting-started/providers/github
25
+ */
26
+ ],
27
+ }
@@ -0,0 +1,21 @@
1
+ import { PrismaClient } from "@prisma/client"
2
+ import { betterAuth } from "better-auth"
3
+ import { prismaAdapter } from "better-auth/adapters/prisma"
4
+ import { nextCookies } from "better-auth/next-js"
5
+
6
+ import { env } from "@/env"
7
+
8
+ const prisma = new PrismaClient()
9
+
10
+ export const auth = betterAuth({
11
+ database: prismaAdapter(prisma, {
12
+ provider: "sqlite",
13
+ }),
14
+ socialProviders: {
15
+ discord: {
16
+ clientId: env.DISCORD_CLIENT_ID,
17
+ clientSecret: env.DISCORD_CLIENT_SECRET,
18
+ },
19
+ },
20
+ plugins: [nextCookies()], // make sure nextCookies() is the last plugin in the array
21
+ })
@@ -0,0 +1,16 @@
1
+ import { betterAuth } from "better-auth"
2
+ import { nextCookies } from "better-auth/next-js"
3
+ import Database from "better-sqlite3"
4
+
5
+ import { env } from "@/env"
6
+
7
+ export const auth = betterAuth({
8
+ database: new Database("./db.sqlite"),
9
+ socialProviders: {
10
+ discord: {
11
+ clientId: env.DISCORD_CLIENT_ID,
12
+ clientSecret: env.DISCORD_CLIENT_SECRET,
13
+ },
14
+ },
15
+ plugins: [nextCookies()], // make sure nextCookies() is the last plugin in the array
16
+ })
@@ -0,0 +1,23 @@
1
+ import { PrismaClient } from "@prisma/client"
2
+
3
+ import { env } from "@/env"
4
+
5
+ const createPrismaClient = () =>
6
+ new PrismaClient({
7
+ log:
8
+ env.NODE_ENV === "development"
9
+ ? [
10
+ // "query",
11
+ "error",
12
+ "warn",
13
+ ]
14
+ : ["error"],
15
+ })
16
+
17
+ const globalForPrisma = globalThis as unknown as {
18
+ prisma: ReturnType<typeof createPrismaClient> | undefined
19
+ }
20
+
21
+ export const db = globalForPrisma.prisma ?? createPrismaClient()
22
+
23
+ if (env.NODE_ENV !== "production") globalForPrisma.prisma = db