@loop/auth
Clerk authentication wrapper for Loop Health Next.js apps. Provides hooks, components, and middleware.
Installation
pnpm add @loop/authExports
Main Export
import { UNAUTHENTICATED, type AuthState, type AuthUser } from '@loop/auth';
// UNAUTHENTICATED is a sentinel value for unauthenticated stateClient Components
import { useAuth, UserButton, SignInButton } from '@loop/auth/client';
// React hook for auth state
const { user, isSignedIn, isLoaded } = useAuth();Middleware
import { clerkMiddleware } from '@loop/auth/middleware';
// In middleware.ts
export default clerkMiddleware;Usage in Next.js
Protecting Pages
// middleware.ts
import { clerkMiddleware, createRouteMatcher } from '@loop/auth/middleware';
const isPublicRoute = createRouteMatcher(['/sign-in(.*)', '/sign-up(.*)', '/']);
export default clerkMiddleware((auth, request) => {
if (!isPublicRoute(request)) {
auth().protect();
}
});Server Components
import { currentUser } from '@clerk/nextjs/server';
export default async function Page() {
const user = await currentUser();
if (!user) return <div>Not signed in</div>;
return <div>Hello {user.firstName}</div>;
}Used By
@loop/auth is used by applications that need Clerk authentication:
- @loop/loop-health — User authentication and SSO
- @loop/loop-health-mobile — Mobile app authentication
- @loop/call-booking — JWT verification for API endpoints
- @loop/my-loop-health — Customer authentication and role-based access