create-next-pro-cli 0.1.13 ā 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/README.md +1 -0
- package/bin.ts +0 -0
- package/install.sh +1 -0
- package/package.json +6 -4
- package/src/index.ts +0 -67
- package/src/lib/addComponent.ts +0 -139
- package/src/lib/addPage.ts +0 -201
- 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.test.ts +0 -23
- package/src/lib/utils.ts +0 -60
- package/src/scaffold-dev.ts +0 -89
- package/src/scaffold.ts +0 -86
- 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/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,86 +0,0 @@
|
|
|
1
|
-
// src/scaffold.ts
|
|
2
|
-
|
|
3
|
-
import { cp, mkdir, rm, writeFile, readFile } 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
|
-
// Apply configuration: add dependencies or files based on prompt choices
|
|
63
|
-
const pkgPath = join(targetPath, "package.json");
|
|
64
|
-
if (existsSync(pkgPath)) {
|
|
65
|
-
const pkg = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
66
|
-
pkg.dependencies = pkg.dependencies || {};
|
|
67
|
-
if (options.useI18n) {
|
|
68
|
-
pkg.dependencies["next-intl"] =
|
|
69
|
-
pkg.dependencies["next-intl"] || "^4.3.5";
|
|
70
|
-
}
|
|
71
|
-
await writeFile(pkgPath, JSON.stringify(pkg, null, 2));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Write CLI configuration to project root
|
|
75
|
-
await writeFile(
|
|
76
|
-
join(targetPath, "cnp.config.json"),
|
|
77
|
-
JSON.stringify(options, null, 2),
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
console.log("ā
Project scaffolded successfully!");
|
|
81
|
-
console.log(`ā”ļø cd ${options.projectName} && bun install && bun dev`);
|
|
82
|
-
} catch (err) {
|
|
83
|
-
console.error("ā Error during scaffolding:", err);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -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
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { MetadataRoute } from "next";
|
|
2
|
-
import { Locale } from "next-intl";
|
|
3
|
-
import { host } from "@/config";
|
|
4
|
-
import { routing } from "@/lib/i18n/routing";
|
|
5
|
-
import { getPathname } from "@/lib/i18n/navigation";
|
|
6
|
-
|
|
7
|
-
export default function sitemap(): MetadataRoute.Sitemap {
|
|
8
|
-
return [...getEntries("/"), ...getEntries("/pathnames")];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type Href = Parameters<typeof getPathname>[0]["href"];
|
|
12
|
-
|
|
13
|
-
function getEntries(href: Href) {
|
|
14
|
-
return routing.locales.map((locale) => ({
|
|
15
|
-
url: getUrl(href, locale),
|
|
16
|
-
alternates: {
|
|
17
|
-
languages: Object.fromEntries(
|
|
18
|
-
routing.locales.map((cur) => [cur, getUrl(href, cur)])
|
|
19
|
-
),
|
|
20
|
-
},
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getUrl(href: Href, locale: Locale) {
|
|
25
|
-
const pathname = getPathname({ locale, href });
|
|
26
|
-
return host + pathname;
|
|
27
|
-
}
|