Clerk Next.js App Router Quickstart

repository·main·Indexed 42 days ago

https://github.com/clerk/clerk-nextjs-app-quickstart

A quickstart template for integrating Clerk authentication and user management into a Next.js application using the App Router. Covers installing the @clerk/nextjs SDK, implementing clerkMiddleware() for route protection, and using the <ClerkProvider /> component.

Tokens
589
Snippets
2
Records
4
Agent score
3%

What's inside Clerk

  1. Quickstart: Integrate Clerk with Next.js App Router

    main

    This quickstart template demonstrates how to integrate Clerk authentication into a Next.js application using the App Router. By following this pattern, you will learn how to:

    1. Install the @clerk/nextjs SDK.
    2. Implement clerkMiddleware() to protect routes.
    3. Wrap your application with <ClerkProvider /> and use pre-built Clerk components (e.g., for sign-in, sign-up, and user profiles).
    4. Manage user sessions and create users.
  2. Run the Clerk Next.js Quickstart template locally

    main

    To run this template on your local machine, follow these steps:

    1. Clone the repository:
      git clone https://github.com/clerk/clerk-nextjs-app-quickstart
    2. Install dependencies using pnpm:
      pnpm install
    3. Start the development server:
      pnpm run dev
    4. Open the application and select the "Sign in" button in the top-right corner to test the authentication flow.
    git clone https://github.com/clerk/clerk-nextjs-app-quickstart
    pnpm install
    pnpm run dev
  3. Configure ESLint for Next.js and TypeScript

    main

    This project uses the new ESLint flat config format via eslint/config. It integrates Next.js Core Web Vitals rules and TypeScript support by spreading eslint-config-next/core-web-vitals and eslint-config-next/typescript into the configuration array.

    To customize which files are globally ignored (overriding the defaults provided by eslint-config-next), use the globalIgnores function within defineConfig.

    import { defineConfig, globalIgnores } from 'eslint/config'
    import nextVitals from 'eslint-config-next/core-web-vitals'
    import nextTs from 'eslint-config-next/typescript'
    
    const eslintConfig = defineConfig([
      ...nextVitals,
      ...nextTs,
      globalIgnores([
        '.next/**',
        'out/**',
        'build/**',
        'next-env.d.ts',
      ]),
    ])
    
    export default eslintConfig