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.
@@ -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,11 +0,0 @@
1
- "use client";
2
-
3
- import { SessionProvider } from "next-auth/react";
4
-
5
- export function AuthSessionProvider({
6
- children,
7
- }: {
8
- children: React.ReactNode;
9
- }) {
10
- return <SessionProvider>{children}</SessionProvider>;
11
- }
@@ -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
- };