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

(/basic-rbac) add middleware, reorg and refactor copy #1560

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

victoriaxyz
Copy link
Contributor

@victoriaxyz victoriaxyz commented Sep 24, 2024

Explanation:

This PR:

  • fixes clarity and flow
  • reorganize sections
  • rename and remove some headings
  • breaks copy into steps
  • add middleware.ts section

Copy link

Hey, here’s your docs preview: https://clerk.com/docs/pr/1560

@victoriaxyz victoriaxyz changed the title update doc refactor content copy and flow, and code Sep 24, 2024
@victoriaxyz victoriaxyz changed the title refactor content copy and flow, and code refactor content copy and code Sep 24, 2024
Copy link
Member

@royanger royanger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guide should probably get a further update, roughly as follows:

  1. Change Create and protect an admin dashboard to something akin to Create and protect an admin dashboard via page.tsx``
  2. Add a section like Create and protect an admin dashboard via Middleware
  3. Be clear the developer only needs to pick one option for a route.
  4. Explain using the checkRole() function in Middleware to protect the entire route. Untested code:
import {
  clerkMiddleware,
  createRouteMatcher
} from '@clerk/nextjs/server';
import { checkRole } from "@/utils/roles";

const isAdminRoute = createRouteMatcher([
  '/admin(.*)',
]);

export default clerkMiddleware((auth, req) => {
  if (isAdminRoute(req) && !checkRole("admin")) auth().protect();
});

export const config = {
  matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
};

Aside from that suggestion, I dropped some thoughts and suggestion throughout the PR.

docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
docs/guides/basic-rbac.mdx Outdated Show resolved Hide resolved
@victoriaxyz victoriaxyz changed the title refactor content copy and code add middleware, reorg and refactor copy Sep 26, 2024
@alexisintech alexisintech changed the title add middleware, reorg and refactor copy (/basic-rbac) add middleware, reorg and refactor copy Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants