Learn how authentication works in the NextCoder platform
NextCoder uses Clerk for authentication, providing secure user management with support for:
Authentication is handled automatically through Clerk's session management. The session is available throughout the application via Clerk's React hooks.
import { useUser } from '@clerk/nextjs';
function MyComponent() {
const { isLoaded, isSignedIn, user } = useUser();
if (!isLoaded) {
return <div>Loading...</div>;
}
if (!isSignedIn) {
return <div>Not signed in</div>;
}
return <div>Hello, {user.firstName}!</div>;
}All API endpoints require authentication through Clerk session cookies. The authentication is handled automatically when making requests from the browser.
Routes are protected using Clerk's middleware. Public routes are explicitly defined in the middleware configuration.
// middleware.ts
import { authMiddleware } from "@clerk/nextjs/server";
export default authMiddleware({
publicRoutes: ["/", "/api/webhooks(.*)", "/pricing"],
});
export const config = {
matcher: ["/((?!.+\.[\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};