Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Clerk's new middleware and auth page props #192

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/commands/add/auth/clerk/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { ComponentLibType } from "../../../../types.js";
import { formatFilePath, getFilePaths } from "../../../filePaths/index.js";

const generateMiddlewareTs = () => {
return `import { authMiddleware } from "@clerk/nextjs";
return `import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';

// This example protects all routes including api/trpc routes
// Please edit this to allow other routes to be public as needed.
// See https://clerk.com/docs/references/nextjs/auth-middleware for more information about configuring your middleware
export default authMiddleware({ ignoredRoutes: ["/"] });
// See https://clerk.com/docs/references/nextjs/clerk-middleware for more information about configuring your middleware
const isProtectedRoute = createRouteMatcher([]);

export default clerkMiddleware((auth, req) => {
if (isProtectedRoute(req)) auth().protect();
});

export const config = {
matcher: ['/((?!.+\\\\\.[\\\\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],
Expand All @@ -19,7 +23,7 @@ const generateSignInPageTs = () => {
export default function Page() {
return (
<main className="grid place-items-center pt-4">
<SignIn redirectUrl={"/dashboard"} />
<SignIn fallbackRedirectUrl={"/dashboard"} />
</main>
);
}`;
Expand All @@ -30,7 +34,7 @@ const generateSignUpPageTs = () => {
export default function Page() {
return (
<main className="grid place-items-center pt-4">
<SignUp redirectUrl={"/dashboard"} />
<SignUp fallbackRedirectUrl={"/dashboard"} />
</main>
);
}`;
Expand Down