create-next-pro-cli 0.1.12 → 0.1.14
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.
- package/.github/workflows/ci.yml +38 -0
- package/README.md +105 -86
- package/bin.ts +0 -0
- package/dist/bin.js +5466 -0
- package/install.sh +64 -8
- package/package.json +9 -3
- package/.husky/commit-msg +0 -2
- package/.husky/pre-commit +0 -2
- package/CODE_OF_CONDUCT.md +0 -33
- package/CONTRIBUTING.md +0 -44
- package/FONCTIONALITY.md +0 -25
- package/src/index.ts +0 -67
- package/src/lib/addComponent.ts +0 -119
- package/src/lib/addPage.ts +0 -170
- package/src/lib/createProject.ts +0 -18
- package/src/lib/createProjectWithPrompt.ts +0 -79
- package/src/lib/rmPage.ts +0 -52
- package/src/lib/utils.ts +0 -36
- package/src/scaffold-dev.ts +0 -89
- package/src/scaffold.ts +0 -70
- package/templates/Projects/default/README.md +0 -36
- package/templates/Projects/default/src/app/[locale]/(public)/Login/page.tsx +0 -6
- package/templates/Projects/default/src/app/[locale]/(public)/Register/page.tsx +0 -6
- package/templates/Projects/default/src/app/[locale]/(public)/_home/loading.tsx +0 -5
- package/templates/Projects/default/src/app/[locale]/(public)/_home/page.tsx +0 -6
- package/templates/Projects/default/src/app/[locale]/(public)/layout.tsx +0 -9
- package/templates/Projects/default/src/app/[locale]/(user)/Dashboard/error.tsx +0 -38
- package/templates/Projects/default/src/app/[locale]/(user)/Dashboard/loading.tsx +0 -10
- package/templates/Projects/default/src/app/[locale]/(user)/Dashboard/page.tsx +0 -5
- package/templates/Projects/default/src/app/[locale]/(user)/Settings/loading.tsx +0 -17
- package/templates/Projects/default/src/app/[locale]/(user)/Settings/page.tsx +0 -6
- package/templates/Projects/default/src/app/[locale]/(user)/UserInfo/loading.tsx +0 -17
- package/templates/Projects/default/src/app/[locale]/(user)/UserInfo/page.tsx +0 -6
- package/templates/Projects/default/src/app/[locale]/(user)/layout.tsx +0 -9
- package/templates/Projects/default/src/app/[locale]/layout.tsx +0 -31
- package/templates/Projects/default/src/app/[locale]/loading.tsx +0 -14
- package/templates/Projects/default/src/app/[locale]/not-found.tsx +0 -22
- package/templates/Projects/default/src/app/[locale]/page.tsx +0 -6
- package/templates/Projects/default/src/app/api/auth/[...nextauth]/route.ts +0 -62
- package/templates/Projects/default/src/app/api/auth/post-login/route.ts +0 -26
- package/templates/Projects/default/src/app/favicon.ico +0 -0
- package/templates/Projects/default/src/app/layout.tsx +0 -11
- package/templates/Projects/default/src/app/not-found.tsx +0 -17
- package/templates/Projects/default/src/app/page.tsx +0 -6
- package/templates/Projects/default/src/app/sitemap.ts +0 -27
- package/templates/Projects/default/src/app/styles/globals.css +0 -305
- package/templates/Projects/default/src/auth.config.ts +0 -0
- package/templates/Projects/default/src/config.ts +0 -4
- package/templates/Projects/default/src/lib/auth/disconnect.ts +0 -11
- package/templates/Projects/default/src/lib/auth/isConnected.ts +0 -18
- package/templates/Projects/default/src/lib/i18n/navigation.ts +0 -19
- package/templates/Projects/default/src/lib/i18n/request.ts +0 -31
- package/templates/Projects/default/src/lib/i18n/routing.ts +0 -20
- package/templates/Projects/default/src/lib/utils.ts +0 -6
- package/templates/Projects/default/src/ui/Dashboard/LogoutButton.tsx +0 -27
- package/templates/Projects/default/src/ui/Dashboard/StatsCard.tsx +0 -14
- package/templates/Projects/default/src/ui/Dashboard/WelcomeCard.tsx +0 -10
- package/templates/Projects/default/src/ui/Dashboard/page-ui.tsx +0 -23
- package/templates/Projects/default/src/ui/Login/page-ui.tsx +0 -22
- package/templates/Projects/default/src/ui/Register/page-ui.tsx +0 -26
- package/templates/Projects/default/src/ui/Settings/page-ui.tsx +0 -17
- package/templates/Projects/default/src/ui/UserInfo/page-ui.tsx +0 -17
- package/templates/Projects/default/src/ui/_global/BackButton.tsx +0 -17
- package/templates/Projects/default/src/ui/_global/Button.tsx +0 -75
- package/templates/Projects/default/src/ui/_global/GlobalHeader.tsx +0 -55
- package/templates/Projects/default/src/ui/_global/GlobalMain.tsx +0 -15
- package/templates/Projects/default/src/ui/_global/Loading.tsx +0 -13
- package/templates/Projects/default/src/ui/_global/LocaleSwitcher.tsx +0 -38
- package/templates/Projects/default/src/ui/_global/PublicNav.tsx +0 -91
- package/templates/Projects/default/src/ui/_global/ThemeToggle.tsx +0 -53
- package/templates/Projects/default/src/ui/_global/UserNav.tsx +0 -35
- package/templates/Projects/default/src/ui/_home/page-ui.tsx +0 -27
package/src/lib/rmPage.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { writeFile, readdir } from "node:fs/promises";
|
|
3
|
-
import prompts from "prompts";
|
|
4
|
-
import { existsSync } from "node:fs";
|
|
5
|
-
|
|
6
|
-
export async function rmPage(args: string[]) {
|
|
7
|
-
let pageName = args[1];
|
|
8
|
-
if (!pageName || pageName.startsWith("-")) {
|
|
9
|
-
const response = await prompts.prompt({
|
|
10
|
-
type: "text",
|
|
11
|
-
name: "pageName",
|
|
12
|
-
message: "🗑️ Page name to remove:",
|
|
13
|
-
validate: (name: string) => (name ? true : "Page name is required"),
|
|
14
|
-
});
|
|
15
|
-
pageName = response.pageName;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Remove translation files messages/<lang>/<PageName>.json
|
|
19
|
-
const messagesPath = join(process.cwd(), "messages");
|
|
20
|
-
const entries = await readdir(messagesPath, { withFileTypes: true });
|
|
21
|
-
const langDirs = entries.filter((e) => e.isDirectory()).map((e) => e.name);
|
|
22
|
-
for (const locale of langDirs) {
|
|
23
|
-
const jsonTarget = join(messagesPath, locale, `${pageName}.json`);
|
|
24
|
-
if (existsSync(jsonTarget)) {
|
|
25
|
-
await writeFile(jsonTarget, "");
|
|
26
|
-
await import("node:child_process").then((cp) =>
|
|
27
|
-
cp.execSync(`rm -f '${jsonTarget}'`)
|
|
28
|
-
);
|
|
29
|
-
console.log(`🗑️ Deleted: ${jsonTarget}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Remove folder src/ui/<PageName>
|
|
34
|
-
const uiPageDir = join(process.cwd(), "src", "ui", pageName);
|
|
35
|
-
if (existsSync(uiPageDir)) {
|
|
36
|
-
await import("node:child_process").then((cp) =>
|
|
37
|
-
cp.execSync(`rm -rf '${uiPageDir}'`)
|
|
38
|
-
);
|
|
39
|
-
console.log(`🗑️ Deleted: ${uiPageDir}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Remove folder src/app/[locale]/<PageName>
|
|
43
|
-
const appLocaleDir = join(process.cwd(), "src", "app", "[locale]", pageName);
|
|
44
|
-
if (existsSync(appLocaleDir)) {
|
|
45
|
-
await import("node:child_process").then((cp) =>
|
|
46
|
-
cp.execSync(`rm -rf '${appLocaleDir}'`)
|
|
47
|
-
);
|
|
48
|
-
console.log(`🗑️ Deleted: ${appLocaleDir}`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log(`✅ Page "${pageName}" deleted.`);
|
|
52
|
-
}
|
package/src/lib/utils.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capitalize the first letter of a string.
|
|
3
|
-
*/
|
|
4
|
-
export function capitalize(str: string): string {
|
|
5
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Map a key to its corresponding file name for page/component templates.
|
|
10
|
-
* @param key string
|
|
11
|
-
* @returns file name string
|
|
12
|
-
*/
|
|
13
|
-
export function toFileName(key: string): string {
|
|
14
|
-
switch (key) {
|
|
15
|
-
case "layout":
|
|
16
|
-
return "layout.tsx";
|
|
17
|
-
case "page":
|
|
18
|
-
return "page.tsx";
|
|
19
|
-
case "loading":
|
|
20
|
-
return "loading.tsx";
|
|
21
|
-
case "not-found":
|
|
22
|
-
return "not-found.tsx";
|
|
23
|
-
case "error":
|
|
24
|
-
return "error.tsx";
|
|
25
|
-
case "global-error":
|
|
26
|
-
return "global-error.tsx";
|
|
27
|
-
case "route":
|
|
28
|
-
return "route.ts";
|
|
29
|
-
case "template":
|
|
30
|
-
return "template.tsx";
|
|
31
|
-
case "default":
|
|
32
|
-
return "default.tsx";
|
|
33
|
-
default:
|
|
34
|
-
return `${key}.tsx`;
|
|
35
|
-
}
|
|
36
|
-
}
|
package/src/scaffold-dev.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// src/scaffold-dev.ts
|
|
2
|
-
|
|
3
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Experimental tool for generating a Next.js project template structure.
|
|
8
|
-
* This script is under development and will evolve to allow creation of new project templates in the future.
|
|
9
|
-
*
|
|
10
|
-
* @param options Object containing the project name
|
|
11
|
-
*/
|
|
12
|
-
async function scaffoldTemplate(options: { projectName: string }) {
|
|
13
|
-
const base = options.projectName;
|
|
14
|
-
console.log(`\n📁 Creating template directory: ${base}`);
|
|
15
|
-
|
|
16
|
-
// List of folders to create for the template
|
|
17
|
-
const folders = [
|
|
18
|
-
"app/[locale]/_main",
|
|
19
|
-
"app/[locale]/dashboard",
|
|
20
|
-
"lib/i18n",
|
|
21
|
-
"messages/en",
|
|
22
|
-
"messages/fr",
|
|
23
|
-
"public",
|
|
24
|
-
"styles",
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
// List of files to create for the template
|
|
28
|
-
const files = [
|
|
29
|
-
"app/[locale]/layout.tsx",
|
|
30
|
-
"app/[locale]/page.tsx",
|
|
31
|
-
"app/[locale]/not-found.tsx",
|
|
32
|
-
"app/[locale]/error.tsx",
|
|
33
|
-
|
|
34
|
-
"app/[locale]/_main/page.tsx",
|
|
35
|
-
"app/[locale]/_main/layout.tsx",
|
|
36
|
-
"app/[locale]/_main/loading.tsx",
|
|
37
|
-
"app/[locale]/_main/template.tsx",
|
|
38
|
-
|
|
39
|
-
"app/[locale]/dashboard/page.tsx",
|
|
40
|
-
"app/[locale]/dashboard/layout.tsx",
|
|
41
|
-
"app/[locale]/dashboard/loading.tsx",
|
|
42
|
-
"app/[locale]/dashboard/template.tsx",
|
|
43
|
-
|
|
44
|
-
"lib/i18n/routing.ts",
|
|
45
|
-
"lib/i18n/request.ts",
|
|
46
|
-
"lib/i18n/navigation.ts",
|
|
47
|
-
|
|
48
|
-
"messages/en/home.json",
|
|
49
|
-
"messages/en/dashboard.json",
|
|
50
|
-
"messages/en/navbar.json",
|
|
51
|
-
|
|
52
|
-
"messages/fr/home.json",
|
|
53
|
-
"messages/fr/dashboard.json",
|
|
54
|
-
"messages/fr/navbar.json",
|
|
55
|
-
|
|
56
|
-
"styles/globals.css",
|
|
57
|
-
"middleware.ts",
|
|
58
|
-
"next.config.ts",
|
|
59
|
-
"postcss.config.mjs",
|
|
60
|
-
"eslint.config.mjs",
|
|
61
|
-
"tailwind.config.ts",
|
|
62
|
-
"tsconfig.json",
|
|
63
|
-
"next-env.d.ts",
|
|
64
|
-
"package.json",
|
|
65
|
-
"README.md",
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
// Create all folders
|
|
69
|
-
for (const folder of folders) {
|
|
70
|
-
await mkdir(join(base, folder), { recursive: true });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Create all files with a placeholder comment
|
|
74
|
-
for (const file of files) {
|
|
75
|
-
const fullPath = join(base, file);
|
|
76
|
-
await writeFile(fullPath, `// ${file}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
console.log("✅ Full template generated.");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Direct execution if this file is run as a script
|
|
83
|
-
if (require.main === module) {
|
|
84
|
-
const projectName = process.argv[2] || "template-next-app";
|
|
85
|
-
scaffoldTemplate({ projectName }).catch((err) => {
|
|
86
|
-
console.error("Error during template generation:", err);
|
|
87
|
-
process.exit(1);
|
|
88
|
-
});
|
|
89
|
-
}
|
package/src/scaffold.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// src/scaffold.ts
|
|
2
|
-
|
|
3
|
-
import { cp, mkdir, rm } from "node:fs/promises";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { existsSync } from "node:fs";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Options for scaffolding a Next.js project.
|
|
9
|
-
*/
|
|
10
|
-
interface ScaffoldOptions {
|
|
11
|
-
projectName: string;
|
|
12
|
-
useTypescript: boolean;
|
|
13
|
-
useEslint: boolean;
|
|
14
|
-
useTailwind: boolean;
|
|
15
|
-
useSrcDir: boolean;
|
|
16
|
-
useTurbopack: boolean;
|
|
17
|
-
useI18n: boolean;
|
|
18
|
-
customAlias: boolean;
|
|
19
|
-
importAlias: string;
|
|
20
|
-
force?: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Scaffold a new Next.js project based on provided options.
|
|
25
|
-
*
|
|
26
|
-
* - Copies the default template to the target directory
|
|
27
|
-
* - Removes the target directory if it exists and --force is set
|
|
28
|
-
* - Optionally customizes the structure in future (e.g. remove unused files)
|
|
29
|
-
*
|
|
30
|
-
* @param options ScaffoldOptions for the project
|
|
31
|
-
*/
|
|
32
|
-
export async function scaffoldProject(options: ScaffoldOptions) {
|
|
33
|
-
const targetPath = join(process.cwd(), options.projectName);
|
|
34
|
-
const templatePath = join(
|
|
35
|
-
import.meta.dir,
|
|
36
|
-
"..",
|
|
37
|
-
"templates",
|
|
38
|
-
"Projects",
|
|
39
|
-
"default"
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
// Check if target directory exists
|
|
43
|
-
if (existsSync(targetPath)) {
|
|
44
|
-
if (options.force) {
|
|
45
|
-
console.warn("⚠️ Target directory already exists, removing...");
|
|
46
|
-
await rm(targetPath, { recursive: true, force: true });
|
|
47
|
-
} else {
|
|
48
|
-
console.error(
|
|
49
|
-
"❌ Target directory already exists. Use --force to overwrite."
|
|
50
|
-
);
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
console.log("📁 Creating project directory...");
|
|
57
|
-
await mkdir(targetPath, { recursive: true });
|
|
58
|
-
|
|
59
|
-
console.log("📦 Copying files from template...");
|
|
60
|
-
await cp(templatePath, targetPath, { recursive: true });
|
|
61
|
-
|
|
62
|
-
// Future customization: remove unused files if useTailwind === false, etc.
|
|
63
|
-
|
|
64
|
-
console.log("✅ Project scaffolded successfully!");
|
|
65
|
-
console.log(`➡️ cd ${options.projectName} && bun install && bun dev`);
|
|
66
|
-
} catch (err) {
|
|
67
|
-
console.error("❌ Error during scaffolding:", err);
|
|
68
|
-
process.exit(1);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// README.mdThis is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-pro`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
|
2
|
-
|
|
3
|
-
## Getting Started
|
|
4
|
-
|
|
5
|
-
First, run the development server:
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm run dev
|
|
9
|
-
# or
|
|
10
|
-
yarn dev
|
|
11
|
-
# or
|
|
12
|
-
pnpm dev
|
|
13
|
-
# or
|
|
14
|
-
bun dev
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
|
18
|
-
|
|
19
|
-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
|
20
|
-
|
|
21
|
-
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
|
22
|
-
|
|
23
|
-
## Learn More
|
|
24
|
-
|
|
25
|
-
To learn more about Next.js, take a look at the following resources:
|
|
26
|
-
|
|
27
|
-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
|
28
|
-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
|
29
|
-
|
|
30
|
-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
|
31
|
-
|
|
32
|
-
## Deploy on Vercel
|
|
33
|
-
|
|
34
|
-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
|
35
|
-
|
|
36
|
-
Check out [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// app/[locale]/error.tsx
|
|
2
|
-
"use client"; // Error boundaries must be Client Components
|
|
3
|
-
|
|
4
|
-
import { useEffect } from "react";
|
|
5
|
-
|
|
6
|
-
export default function Error({
|
|
7
|
-
error,
|
|
8
|
-
reset,
|
|
9
|
-
}: {
|
|
10
|
-
error: Error & { digest?: string };
|
|
11
|
-
reset: () => void;
|
|
12
|
-
}) {
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
// Log the error to an error reporting service
|
|
15
|
-
console.error(error);
|
|
16
|
-
}, [error]);
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<div>
|
|
20
|
-
<h2>Something went wrong!</h2>
|
|
21
|
-
<button
|
|
22
|
-
onClick={
|
|
23
|
-
// Attempt to recover by trying to re-render the segment
|
|
24
|
-
() => reset()
|
|
25
|
-
}
|
|
26
|
-
>
|
|
27
|
-
Try again
|
|
28
|
-
</button>
|
|
29
|
-
</div>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
// This page is used to handle errors in the application
|
|
33
|
-
// You can customize this page to display a user-friendly error message
|
|
34
|
-
// or redirect to a different page if needed
|
|
35
|
-
// This is part of the Next.js app directory structure and will be automatically used by Next.js
|
|
36
|
-
// when an error occurs in the application
|
|
37
|
-
// Make sure to handle errors gracefully to improve user experience
|
|
38
|
-
// You can also log errors or send them to an error tracking service
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// app/[locale]/dashboard/loading.tsx
|
|
2
|
-
"use client";
|
|
3
|
-
|
|
4
|
-
export default function Loading() {
|
|
5
|
-
return (
|
|
6
|
-
<div className="flex flex-col flex-1 items-center justify-center">
|
|
7
|
-
<p className="text-gray-500">Loading user info...</p>
|
|
8
|
-
</div>
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
// This component is used to show a loading state while the dashboard is being prepared
|
|
12
|
-
// You can customize it with a spinner, skeletons, or any loading UI you prefer
|
|
13
|
-
// It will be displayed when the dashboard is loading, for example during data fetching or component rendering
|
|
14
|
-
// This is useful for providing feedback to users that something is happening in the background
|
|
15
|
-
// You can also use this to implement a more complex loading state with animations or placeholders
|
|
16
|
-
// Make sure to keep it lightweight to avoid blocking the main thread
|
|
17
|
-
// This component is part of the Next.js app directory structure and will be automatically used by Next.js
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// app/[locale]/dashboard/loading.tsx
|
|
2
|
-
"use client";
|
|
3
|
-
|
|
4
|
-
export default function Loading() {
|
|
5
|
-
return (
|
|
6
|
-
<div className="flex flex-col flex-1 items-center justify-center">
|
|
7
|
-
<p className="text-gray-500">Loading user info...</p>
|
|
8
|
-
</div>
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
// This component is used to show a loading state while the dashboard is being prepared
|
|
12
|
-
// You can customize it with a spinner, skeletons, or any loading UI you prefer
|
|
13
|
-
// It will be displayed when the dashboard is loading, for example during data fetching or component rendering
|
|
14
|
-
// This is useful for providing feedback to users that something is happening in the background
|
|
15
|
-
// You can also use this to implement a more complex loading state with animations or placeholders
|
|
16
|
-
// Make sure to keep it lightweight to avoid blocking the main thread
|
|
17
|
-
// This component is part of the Next.js app directory structure and will be automatically used by Next.js
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// app/[locale]/layout.tsx
|
|
2
|
-
import { NextIntlClientProvider } from "next-intl";
|
|
3
|
-
import { setRequestLocale } from "next-intl/server";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import "@/app/styles/globals.css"; // Import global styles
|
|
6
|
-
import GlobalHeader from "@/ui/_global/GlobalHeader";
|
|
7
|
-
import GlobalMain from "@/ui/_global/GlobalMain";
|
|
8
|
-
import { isConnected } from "@/lib/auth/isConnected";
|
|
9
|
-
|
|
10
|
-
export default async function LocaleLayout({
|
|
11
|
-
children,
|
|
12
|
-
params,
|
|
13
|
-
}: {
|
|
14
|
-
children: React.ReactNode;
|
|
15
|
-
params: Promise<{ locale: string }>;
|
|
16
|
-
}) {
|
|
17
|
-
const { locale } = await params;
|
|
18
|
-
setRequestLocale(locale);
|
|
19
|
-
const isConnectedInitial = await isConnected();
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<html lang={locale}>
|
|
23
|
-
<body>
|
|
24
|
-
<NextIntlClientProvider>
|
|
25
|
-
<GlobalHeader isConnectedInitial={isConnectedInitial} />
|
|
26
|
-
<GlobalMain>{children}</GlobalMain>
|
|
27
|
-
</NextIntlClientProvider>
|
|
28
|
-
</body>
|
|
29
|
-
</html>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// app/[locale]/dashboard/loading.tsx
|
|
2
|
-
|
|
3
|
-
import LoadingUI from "@/ui/_global/Loading";
|
|
4
|
-
|
|
5
|
-
export default function Loading() {
|
|
6
|
-
return <LoadingUI />;
|
|
7
|
-
}
|
|
8
|
-
// This component is used to show a loading state while the dashboard is being prepared
|
|
9
|
-
// You can customize it with a spinner, skeletons, or any loading UI you prefer
|
|
10
|
-
// It will be displayed when the dashboard is loading, for example during data fetching or component rendering
|
|
11
|
-
// This is useful for providing feedback to users that something is happening in the background
|
|
12
|
-
// You can also use this to implement a more complex loading state with animations or placeholders
|
|
13
|
-
// Make sure to keep it lightweight to avoid blocking the main thread
|
|
14
|
-
// This component is part of the Next.js app directory structure and will be automatically used by Next.js
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// app/[locale]/not-found.tsx
|
|
2
|
-
import { Link } from "@/lib/i18n/navigation";
|
|
3
|
-
|
|
4
|
-
export default function NotFound() {
|
|
5
|
-
return (
|
|
6
|
-
<div>
|
|
7
|
-
<h2>Not Found</h2>
|
|
8
|
-
<p>Could not find requested resource</p>
|
|
9
|
-
<Link href="/">Return Home</Link>
|
|
10
|
-
</div>
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
// This page is used to handle 404 errors in the application
|
|
14
|
-
// You can customize this page to display a user-friendly error message
|
|
15
|
-
// or redirect to a different page if needed
|
|
16
|
-
// This is part of the Next.js app directory structure and will be automatically used by Next.js
|
|
17
|
-
// when a requested page is not found
|
|
18
|
-
// Make sure to handle 404 errors gracefully to improve user experience
|
|
19
|
-
// You can also log errors or send them to an error tracking service
|
|
20
|
-
// This component can be styled with CSS or Tailwind CSS to match your application's design
|
|
21
|
-
// You can also add additional links or actions for the user to take, such as searching or navigating to other parts of the site
|
|
22
|
-
// This component is lightweight and does not block the main thread
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import NextAuth from "next-auth";
|
|
2
|
-
import type {
|
|
3
|
-
NextAuthOptions,
|
|
4
|
-
Session,
|
|
5
|
-
User,
|
|
6
|
-
Account,
|
|
7
|
-
Profile,
|
|
8
|
-
} from "next-auth";
|
|
9
|
-
import GoogleProvider from "next-auth/providers/google";
|
|
10
|
-
import type { JWT } from "next-auth/jwt";
|
|
11
|
-
|
|
12
|
-
const authOptions: NextAuthOptions = {
|
|
13
|
-
providers: [
|
|
14
|
-
GoogleProvider({
|
|
15
|
-
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
16
|
-
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
17
|
-
}),
|
|
18
|
-
],
|
|
19
|
-
callbacks: {
|
|
20
|
-
async jwt({ token, user }: { token: JWT; user?: User }) {
|
|
21
|
-
if (user) {
|
|
22
|
-
token.id = user.id;
|
|
23
|
-
token.email = user.email;
|
|
24
|
-
token.name = user.name;
|
|
25
|
-
}
|
|
26
|
-
console.log("JWT Callback:", token);
|
|
27
|
-
|
|
28
|
-
return token;
|
|
29
|
-
},
|
|
30
|
-
async session({ session, token }: { session: Session; token: JWT }) {
|
|
31
|
-
if (session.user) {
|
|
32
|
-
session.user.email = token.email;
|
|
33
|
-
session.user.name = token.name;
|
|
34
|
-
}
|
|
35
|
-
return session;
|
|
36
|
-
},
|
|
37
|
-
async signIn({
|
|
38
|
-
user,
|
|
39
|
-
account,
|
|
40
|
-
profile,
|
|
41
|
-
email,
|
|
42
|
-
credentials,
|
|
43
|
-
}: {
|
|
44
|
-
user: User;
|
|
45
|
-
account: Account | null;
|
|
46
|
-
profile?: Profile;
|
|
47
|
-
email?: string | { verificationRequest?: boolean };
|
|
48
|
-
credentials?: Record<string, unknown>;
|
|
49
|
-
}) {
|
|
50
|
-
return true;
|
|
51
|
-
},
|
|
52
|
-
async redirect({ url, baseUrl }: { url: string; baseUrl: string }) {
|
|
53
|
-
const customCallbackRoute = "/api/auth/post-login";
|
|
54
|
-
|
|
55
|
-
return baseUrl + customCallbackRoute;
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const handler = NextAuth(authOptions);
|
|
61
|
-
|
|
62
|
-
export { handler as GET, handler as POST };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { getToken } from "next-auth/jwt";
|
|
2
|
-
import { sign } from "jsonwebtoken";
|
|
3
|
-
import { NextResponse, NextRequest } from "next/server";
|
|
4
|
-
import { redirect } from "@/lib/i18n/navigation";
|
|
5
|
-
|
|
6
|
-
export async function GET(req: NextRequest) {
|
|
7
|
-
const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });
|
|
8
|
-
if (token) {
|
|
9
|
-
const appJwt = sign(
|
|
10
|
-
{ id: token.id, email: token.email, name: token.name },
|
|
11
|
-
process.env.APP_JWT_SECRET!,
|
|
12
|
-
{ expiresIn: "7d" }
|
|
13
|
-
);
|
|
14
|
-
const res = NextResponse.redirect(req.nextUrl.origin + "/");
|
|
15
|
-
res.cookies.set("access_token", appJwt, {
|
|
16
|
-
httpOnly: true,
|
|
17
|
-
secure: process.env.NODE_ENV === "production",
|
|
18
|
-
sameSite: "strict",
|
|
19
|
-
path: "/",
|
|
20
|
-
maxAge: 60 * 60 * 24 * 7,
|
|
21
|
-
});
|
|
22
|
-
return res;
|
|
23
|
-
}
|
|
24
|
-
// Si pas de token, redirige vers login
|
|
25
|
-
return redirect({ href: "/login", locale: "en" });
|
|
26
|
-
}
|
|
Binary file
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// Since we have a `not-found.tsx` page on the root, a layout file
|
|
8
|
-
// is required, even if it's just passing children through.
|
|
9
|
-
export default function RootLayout({ children }: Props) {
|
|
10
|
-
return children;
|
|
11
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import Error from "next/error";
|
|
4
|
-
|
|
5
|
-
// This page renders when a route like `/unknown.txt` is requested.
|
|
6
|
-
// In this case, the layout at `app/[locale]/layout.tsx` receives
|
|
7
|
-
// an invalid value as the `[locale]` param and calls `notFound()`.
|
|
8
|
-
|
|
9
|
-
export default function GlobalNotFound() {
|
|
10
|
-
return (
|
|
11
|
-
<html lang="en">
|
|
12
|
-
<body>
|
|
13
|
-
<Error statusCode={404} />;
|
|
14
|
-
</body>
|
|
15
|
-
</html>
|
|
16
|
-
);
|
|
17
|
-
}
|