stackpatch 1.2.5 → 1.2.7
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/boilerplate/template/app/page.tsx +3 -30
- package/dist/stackpatch.js +69 -3
- package/package.json +1 -1
|
@@ -1,32 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
return (
|
|
3
|
-
<div className="min-h-screen p-8">
|
|
4
|
-
<div className="max-w-4xl mx-auto space-y-8">
|
|
5
|
-
<div>
|
|
6
|
-
<h1 className="text-4xl font-bold mb-4">Welcome to Your StackPatch Project</h1>
|
|
7
|
-
<p className="text-lg text-gray-600 dark:text-gray-400 mb-8">
|
|
8
|
-
Your project has been set up with StackPatch. Get started by adding features to your app.
|
|
9
|
-
</p>
|
|
10
|
-
</div>
|
|
11
|
-
|
|
12
|
-
<div className="border rounded-lg p-6">
|
|
13
|
-
<h2 className="text-2xl font-semibold mb-4">Get Started</h2>
|
|
14
|
-
<p className="text-gray-600 dark:text-gray-400 mb-4">
|
|
15
|
-
Add production-ready features to your app using the StackPatch CLI.
|
|
16
|
-
</p>
|
|
17
|
-
<div className="bg-gray-100 dark:bg-gray-800 p-4 rounded-lg font-mono text-sm">
|
|
18
|
-
<code>npx stackpatch add auth-ui</code>
|
|
19
|
-
</div>
|
|
20
|
-
</div>
|
|
1
|
+
import { redirect } from "next/navigation";
|
|
21
2
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<ul className="list-disc list-inside space-y-2 text-gray-600 dark:text-gray-400">
|
|
25
|
-
<li>Authentication (auth-ui) - Login, signup, and protected routes</li>
|
|
26
|
-
<li>More features coming soon...</li>
|
|
27
|
-
</ul>
|
|
28
|
-
</div>
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
);
|
|
3
|
+
export default function Home() {
|
|
4
|
+
redirect("/stackpatch");
|
|
32
5
|
}
|
package/dist/stackpatch.js
CHANGED
|
@@ -2059,6 +2059,15 @@ function scanProject(target) {
|
|
|
2059
2059
|
};
|
|
2060
2060
|
if (deps.next || deps["next"]) {
|
|
2061
2061
|
scan.framework = "nextjs";
|
|
2062
|
+
// Extract Next.js version
|
|
2063
|
+
const nextVersion = deps.next || deps["next"];
|
|
2064
|
+
if (typeof nextVersion === "string") {
|
|
2065
|
+
// Extract version number (handle ranges like "^16.0.0" or "16.0.0")
|
|
2066
|
+
const versionMatch = nextVersion.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
2067
|
+
if (versionMatch) {
|
|
2068
|
+
scan.nextVersion = versionMatch[0];
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2062
2071
|
}
|
|
2063
2072
|
// Detect package manager from lock files
|
|
2064
2073
|
if (fs.existsSync(path.join(target, "pnpm-lock.yaml"))) {
|
|
@@ -2610,7 +2619,22 @@ function generateMiddleware(target, config, scan) {
|
|
|
2610
2619
|
if (config.protectedRoutes.length === 0) {
|
|
2611
2620
|
return null;
|
|
2612
2621
|
}
|
|
2613
|
-
|
|
2622
|
+
// Next.js 16+ uses proxy.ts instead of middleware.ts
|
|
2623
|
+
const isNext16Plus = scan.nextVersion &&
|
|
2624
|
+
(parseInt(scan.nextVersion.split(".")[0]) >= 16);
|
|
2625
|
+
const middlewareFileName = isNext16Plus ? "proxy.ts" : "middleware.ts";
|
|
2626
|
+
const middlewarePath = path.join(target, middlewareFileName);
|
|
2627
|
+
// Also check for the old filename if migrating
|
|
2628
|
+
const oldMiddlewarePath = path.join(target, isNext16Plus ? "middleware.ts" : "proxy.ts");
|
|
2629
|
+
if (fs.existsSync(oldMiddlewarePath) && oldMiddlewarePath !== middlewarePath) {
|
|
2630
|
+
// Remove old middleware file if it exists
|
|
2631
|
+
try {
|
|
2632
|
+
fs.unlinkSync(oldMiddlewarePath);
|
|
2633
|
+
}
|
|
2634
|
+
catch {
|
|
2635
|
+
// Ignore errors
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2614
2638
|
// Check if middleware already exists
|
|
2615
2639
|
if (fs.existsSync(middlewarePath)) {
|
|
2616
2640
|
// Try to update existing middleware
|
|
@@ -2638,7 +2662,46 @@ function generateMiddleware(target, config, scan) {
|
|
|
2638
2662
|
// Add auth pages to matcher so we can redirect authenticated users away
|
|
2639
2663
|
const authPages = ["/auth/login", "/auth/signup"];
|
|
2640
2664
|
const allMatcherPatterns = [...matcherPatterns, ...authPages];
|
|
2641
|
-
|
|
2665
|
+
// Next.js 16+ uses proxy.ts with default export
|
|
2666
|
+
const middlewareContent = isNext16Plus
|
|
2667
|
+
? `import { NextRequest, NextResponse } from "next/server";
|
|
2668
|
+
import { getSessionCookie } from "better-auth/cookies";
|
|
2669
|
+
|
|
2670
|
+
export default async function handler(request: NextRequest) {
|
|
2671
|
+
const pathname = request.nextUrl.pathname;
|
|
2672
|
+
|
|
2673
|
+
// Check if session cookie exists
|
|
2674
|
+
const sessionCookie = getSessionCookie(request);
|
|
2675
|
+
|
|
2676
|
+
// Handle auth pages (login/signup)
|
|
2677
|
+
if (pathname === "/auth/login" || pathname === "/auth/signup") {
|
|
2678
|
+
// If already authenticated, redirect away from auth pages
|
|
2679
|
+
if (sessionCookie) {
|
|
2680
|
+
const redirectParam = request.nextUrl.searchParams.get("redirect");
|
|
2681
|
+
const redirectTo = redirectParam || "/stackpatch";
|
|
2682
|
+
return NextResponse.redirect(new URL(redirectTo, request.url));
|
|
2683
|
+
}
|
|
2684
|
+
// Not authenticated - allow access to auth pages
|
|
2685
|
+
return NextResponse.next();
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
// Handle protected routes (only protected routes reach here thanks to matcher)
|
|
2689
|
+
if (!sessionCookie) {
|
|
2690
|
+
// Not authenticated - redirect to login with return URL
|
|
2691
|
+
const loginUrl = new URL("/auth/login", request.url);
|
|
2692
|
+
loginUrl.searchParams.set("redirect", pathname);
|
|
2693
|
+
return NextResponse.redirect(loginUrl);
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
// Authenticated and accessing protected route - allow access
|
|
2697
|
+
return NextResponse.next();
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
export const config = {
|
|
2701
|
+
matcher: ${JSON.stringify(allMatcherPatterns)}, // Protected routes + auth pages
|
|
2702
|
+
};
|
|
2703
|
+
`
|
|
2704
|
+
: `import { NextRequest, NextResponse } from "next/server";
|
|
2642
2705
|
import { getSessionCookie } from "better-auth/cookies";
|
|
2643
2706
|
|
|
2644
2707
|
export async function middleware(request: NextRequest) {
|
|
@@ -3208,7 +3271,10 @@ function showSuccessMessage(target, config, scan) {
|
|
|
3208
3271
|
console.log(chalk$1.white(` - ${libDir}/auth-client.ts`));
|
|
3209
3272
|
console.log(chalk$1.white(` - app/api/auth/[...all]/route.ts`));
|
|
3210
3273
|
if (config.protectedRoutes.length > 0) {
|
|
3211
|
-
|
|
3274
|
+
const middlewareFileName = scan.nextVersion && parseInt(scan.nextVersion.split(".")[0]) >= 16
|
|
3275
|
+
? "proxy.ts"
|
|
3276
|
+
: "middleware.ts";
|
|
3277
|
+
console.log(chalk$1.white(` - ${middlewareFileName}`));
|
|
3212
3278
|
}
|
|
3213
3279
|
if (config.protectedRoutes.length > 0) {
|
|
3214
3280
|
console.log(chalk$1.white(` - ${libDir}/protected-routes.ts`));
|
package/package.json
CHANGED