stackpatch 1.2.3 → 1.2.4
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 -1
- package/boilerplate/auth/app/auth/login/page.tsx +50 -24
- package/boilerplate/auth/app/auth/signup/page.tsx +69 -56
- package/boilerplate/auth/app/stackpatch/page.tsx +269 -0
- package/boilerplate/auth/components/auth-wrapper.tsx +61 -0
- package/dist/stackpatch.js +2386 -28430
- package/package.json +6 -3
- package/boilerplate/auth/app/api/auth/[...nextauth]/route.ts +0 -124
- package/boilerplate/auth/app/api/auth/signup/route.ts +0 -45
- package/boilerplate/auth/app/dashboard/page.tsx +0 -82
- package/boilerplate/auth/app/login/page.tsx +0 -136
- package/boilerplate/auth/app/page.tsx +0 -48
- package/boilerplate/auth/components/auth-button.tsx +0 -43
- package/boilerplate/auth/components/auth-navbar.tsx +0 -118
- package/boilerplate/auth/components/protected-route.tsx +0 -74
- package/boilerplate/auth/components/session-provider.tsx +0 -11
- package/boilerplate/auth/middleware.ts +0 -51
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useSession } from "next-auth/react";
|
|
4
|
-
import { useRouter } from "next/navigation";
|
|
5
|
-
import { useEffect } from "react";
|
|
6
|
-
|
|
7
|
-
interface ProtectedRouteProps {
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
redirectTo?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* ProtectedRoute Component
|
|
14
|
-
*
|
|
15
|
-
* Wrap any component or page with this to protect it from unauthorized access.
|
|
16
|
-
*
|
|
17
|
-
* Usage:
|
|
18
|
-
* ```tsx
|
|
19
|
-
* import { ProtectedRoute } from "@/components/protected-route";
|
|
20
|
-
*
|
|
21
|
-
* export default function DashboardPage() {
|
|
22
|
-
* return (
|
|
23
|
-
* <ProtectedRoute>
|
|
24
|
-
* <div>Your protected content here</div>
|
|
25
|
-
* </ProtectedRoute>
|
|
26
|
-
* );
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* Or protect an entire page:
|
|
31
|
-
* ```tsx
|
|
32
|
-
* // app/dashboard/page.tsx
|
|
33
|
-
* import { ProtectedRoute } from "@/components/protected-route";
|
|
34
|
-
*
|
|
35
|
-
* export default function Dashboard() {
|
|
36
|
-
* return (
|
|
37
|
-
* <ProtectedRoute>
|
|
38
|
-
* <h1>Dashboard</h1>
|
|
39
|
-
* <p>This page is protected</p>
|
|
40
|
-
* </ProtectedRoute>
|
|
41
|
-
* );
|
|
42
|
-
* }
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export function ProtectedRoute({
|
|
46
|
-
children,
|
|
47
|
-
redirectTo = "/auth/login"
|
|
48
|
-
}: ProtectedRouteProps) {
|
|
49
|
-
const { data: session, status } = useSession();
|
|
50
|
-
const router = useRouter();
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (status === "unauthenticated") {
|
|
54
|
-
router.push(redirectTo);
|
|
55
|
-
}
|
|
56
|
-
}, [status, router, redirectTo]);
|
|
57
|
-
|
|
58
|
-
if (status === "loading") {
|
|
59
|
-
return (
|
|
60
|
-
<div className="flex min-h-screen items-center justify-center">
|
|
61
|
-
<div className="text-center">
|
|
62
|
-
<div className="inline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]"></div>
|
|
63
|
-
<p className="mt-4 text-sm text-zinc-600 dark:text-zinc-400">Loading...</p>
|
|
64
|
-
</div>
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (status === "unauthenticated") {
|
|
70
|
-
return null; // Will redirect
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return <>{children}</>;
|
|
74
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { withAuth } from "next-auth/middleware";
|
|
2
|
-
import { NextResponse } from "next/server";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Middleware for Protected Routes
|
|
6
|
-
*
|
|
7
|
-
* This middleware protects routes at the file system level.
|
|
8
|
-
*
|
|
9
|
-
* To protect a route, add it to the matcher array below.
|
|
10
|
-
*
|
|
11
|
-
* Example:
|
|
12
|
-
* - To protect all routes under /dashboard: matcher: ["/dashboard/:path*"]
|
|
13
|
-
* - To protect specific routes: matcher: ["/dashboard", "/profile", "/settings"]
|
|
14
|
-
* - To protect all routes except public ones: matcher: ["/((?!api|auth|_next/static|_next/image|favicon.ico).*)"]
|
|
15
|
-
*
|
|
16
|
-
* Protected routes will automatically redirect to /auth/login if user is not authenticated.
|
|
17
|
-
*
|
|
18
|
-
* Usage:
|
|
19
|
-
* 1. Add your protected route paths to the matcher array
|
|
20
|
-
* 2. Users accessing these routes will be redirected to login if not authenticated
|
|
21
|
-
* 3. Authenticated users can access the routes normally
|
|
22
|
-
*/
|
|
23
|
-
export default withAuth(
|
|
24
|
-
function middleware(req) {
|
|
25
|
-
// You can add additional logic here if needed
|
|
26
|
-
// For example, role-based access control
|
|
27
|
-
return NextResponse.next();
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
callbacks: {
|
|
31
|
-
authorized: ({ token }) => !!token, // User must be authenticated
|
|
32
|
-
},
|
|
33
|
-
pages: {
|
|
34
|
-
signIn: "/auth/login", // Redirect to login page
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
// Configure which routes to protect
|
|
40
|
-
// Add your protected routes here
|
|
41
|
-
export const config = {
|
|
42
|
-
matcher: [
|
|
43
|
-
// Example: Protect dashboard routes
|
|
44
|
-
// "/dashboard/:path*",
|
|
45
|
-
// "/profile/:path*",
|
|
46
|
-
// "/settings/:path*",
|
|
47
|
-
|
|
48
|
-
// To protect all routes except public ones, uncomment:
|
|
49
|
-
// "/((?!api|auth|_next/static|_next/image|favicon.ico).*)",
|
|
50
|
-
],
|
|
51
|
-
};
|