ShiftFast Docs

Authentication

How Clerk handles sign-in, sign-up, and route protection.

Clerk handles sign-in, sign-up, sessions, and organizations. You configure it in the Clerk Dashboard (see Setup); this page covers how the app uses it. For why the kit is built around organizations rather than users, see Multi-Tenant Auth with Clerk Organizations, and for how Clerk compares with a self-hosted library, see Clerk vs Better Auth for B2B SaaS.

Protected routes

src/proxy.ts (Next.js 16's name for middleware.ts) combines Clerk's middleware with next-intl's locale middleware and a content security policy. It protects every route under /app, in any locale, before the request reaches a page:

const isProtectedRoute = createRouteMatcher([
  '/app(.*)', // default locale — no prefix
  '/(\\w{2})/app(.*)', // any locale prefix e.g. /fr/app/...
])

Signed-out visitors are redirected to /sign-in. Anything you add under src/app/[locale]/(saas)/app/ is protected automatically.

Sign-in and sign-up

Pages live under src/app/[locale]/(auth)/sign-in/ and sign-up/, rendering Clerk's <SignIn> and <SignUp> components. The sign-in/sign-up URLs and post-auth redirects are hardcoded props on <ClerkProvider> in src/app/[locale]/layout.tsx, not environment variables:

<ClerkProvider
  signInUrl="/sign-in"
  signUpUrl="/sign-up"
  signInFallbackRedirectUrl="/app/dashboard"
  signUpFallbackRedirectUrl={getSignupRedirectPath()}
  afterSignOutUrl="/sign-in"
  // ...
>

Sign-in lands on /app/dashboard. Sign-up does too, unless a plan in src/config/billing.ts is marked isDefault — then new users go straight to Stripe Checkout for it (see Billing). Buttons that lead to a specific plan pass their own redirect_url, which takes priority.

What renders on the dashboard depends on billing state: with a free plan configured, a fresh organization falls back to it; without one, (gated)/layout.tsx renders <UpgradeGate> instead of the real dashboard until the organization picks a plan.

Clerk sends an already signed-in user who opens /sign-up to signUpFallbackRedirectUrl too. That's why the marketing site's "Get started" buttons (get-started-button.tsx) link signed-in users straight to the dashboard instead of to sign-up.

Account menu

The app sidebar (nav-user.tsx) renders Clerk's <UserButton> — the account menu, styled with the appearance prop to match the sidebar. userProfileMode="navigation" points its profile link at /app/account instead of opening Clerk's modal profile UI. The same sidebar also renders <OrganizationSwitcher> — see Organizations for how that's configured.

Account management

src/app/[locale]/(saas)/app/account/[[...rest]]/ renders Clerk's account management UI (profile, security) for the signed-in user.

Server and client APIs

auth() (from @clerk/nextjs/server) is the main entry point in Server Components, Server Actions, and layouts. The codebase uses it for:

  • Scoping data by organization — const { orgId } = await auth(), then querying billing/data by that orgId ((saas)/layout.tsx, (gated)/layout.tsx).
  • Role checks in Server Actions — has({ role: 'org:admin' }) gates admin-only Server Actions; see Organizations for where this pattern is used (billing management).
  • Reading the role directly — const { orgRole } = await auth() decides whether to render admin-only sidebar items (isAdmin={orgRole === 'org:admin'} in (saas)/layout.tsx).

Client-side, two hooks cover what the UI needs:

  • useAuth() — isSignedIn decides where plan and "Get started" buttons link: signed-out visitors go through sign-up first (plan-action-button.tsx, get-started-button.tsx).
  • useUser() — user.fullName, user.firstName, and user.primaryEmailAddress populate the sidebar's account row while <UserButton>'s own avatar loads (nav-user.tsx).

Clerk also exposes currentUser() server-side and useOrganization() / useClerk() client-side for cases this kit doesn't need yet — see Clerk's Next.js SDK reference for the full API.

On this page