Clerk Hello World

VerifiedSafe

Create your first authenticated request with Clerk to verify integration. Ideal for initial API calls and testing authentication.

Sby Skills Guide Bot
SecurityBeginner
7/27/2026
Claude CodeCodex
#authentication#clerk#nextjs#protected-routes#api-security

Recommended for

Automated summary

This skill walks through building a first authenticated request with Clerk to confirm the integration works, using a protected page, an API route, and a client-side test component.

Strengths

  • Provides complete, copy-pasteable TypeScript examples for Next.js App Router: protected page, API route, and client hooks
  • Also covers an Express.js variant with clerkMiddleware and requireAuth
  • Includes an error-handling table for common failures (null userId, expired session, 401, hydration error)
  • Acts as a fast smoke test after installing and configuring environment variables

Limitations

  • Assumes the Clerk SDK is already installed and ClerkProvider wraps the app
  • Does not cover middleware configuration, redirect strategies, or advanced roles/permissions
  • One code snippet contains a stray Python-style comment inside TypeScript
When to use it

Reach for it right after installing and configuring Clerk, to prove end-to-end that an authenticated request succeeds.

When not to use it

Skip it if you need fine-grained authorization design, multi-tenant organizations, or frameworks other than Next.js and Express.

Security analysis

Safe
Quality score88/100

The skill only provides code examples for creating authenticated pages and API routes using Clerk. It does not instruct destructive actions, data exfiltration, or obfuscated commands. The allowed Bash tool is limited to npm commands and is not used in a risky way. The only network call is a client-side fetch to the user's own API endpoint.

No concerns found

How this analysis is made

Examples

First authenticated request
Create a protected Next.js dashboard page and an /api/hello route with Clerk, then show me how to call the API with a token to verify auth works.
Debug 401 on protected route
My Clerk-protected API route keeps returning 401 Unauthorized — walk me through checking the auth() call and the Authorization header.
Express smoke test
Add a Clerk-protected endpoint to my Express app using clerkMiddleware and requireAuth, and show a quick way to test it.

name: clerk-hello-world description: | Create your first authenticated request with Clerk. Use when making initial API calls, testing authentication, or verifying Clerk integration works correctly. Trigger with phrases like "clerk hello world", "first clerk request", "test clerk auth", "verify clerk setup". allowed-tools: Read, Write, Edit, Bash(npm:*), Grep version: 1.0.0 license: MIT author: Jeremy Longshore jeremy@intentsolutions.io compatible-with: claude-code, codex, openclaw

Clerk Hello World

Overview

Make your first authenticated request using Clerk to verify the integration works.

Prerequisites

  • Clerk SDK installed (clerk-install-auth completed)
  • Environment variables configured
  • ClerkProvider wrapping application

Instructions

Step 1: Create Protected Page

// app/dashboard/page.tsx
import { auth, currentUser } from '@clerk/nextjs/server'

export default async function DashboardPage() {
  const { userId } = await auth()
  const user = await currentUser()

  if (!userId) {
    return <div>Please sign in to access this page</div>
  }

  return (
    <div>
      <h1>Hello, {user?.firstName || 'User'}!</h1>
      <p>Your user ID: {userId}</p>
      <p>Email: {user?.emailAddresses[0]?.emailAddress}</p>
    </div>
  )
}

Step 2: Create Protected API Route

// app/api/hello/route.ts
import { auth } from '@clerk/nextjs/server'

export async function GET() {
  const { userId } = await auth()

  if (!userId) {
    return Response.json({ error: 'Unauthorized' }, { status: 401 })  # HTTP 401 Unauthorized
  }

  return Response.json({
    message: 'Hello from Clerk!',
    userId,
    timestamp: new Date().toISOString()
  })
}

Step 3: Test Authentication Flow

// Client-side test component
'use client'
import { useUser, useAuth } from '@clerk/nextjs'

export function AuthTest() {
  const { user, isLoaded, isSignedIn } = useUser()
  const { getToken } = useAuth()

  if (!isLoaded) return <div>Loading...</div>
  if (!isSignedIn) return <div>Not signed in</div>

  const testAPI = async () => {
    const token = await getToken()
    const res = await fetch('/api/hello', {
      headers: { Authorization: `Bearer ${token}` }
    })
    console.log(await res.json())
  }

  return (
    <div>
      <p>Signed in as: {user.primaryEmailAddress?.emailAddress}</p>
      <button onClick={testAPI}>Test API</button>
    </div>
  )
}

Output

  • Protected page showing user information
  • API route returning authenticated user data
  • Successful request/response verification

Error Handling

| Error | Cause | Solution | |-------|-------|----------| | userId is null | User not authenticated | Redirect to sign-in or check middleware | | currentUser returns null | Session expired | Refresh page or re-authenticate | | 401 Unauthorized | Token missing or invalid | Check Authorization header | | Hydration Error | Server/client mismatch | Use 'use client' for client hooks |

Examples

Using with React Hooks

'use client'
import { useUser, useClerk } from '@clerk/nextjs'

export function UserProfile() {
  const { user } = useUser()
  const { signOut } = useClerk()

  return (
    <div>
      <img src={user?.imageUrl} alt="Profile" />
      <h2>{user?.fullName}</h2>
      <button onClick={() => signOut()}>Sign Out</button>
    </div>
  )
}

Express.js Example

import { clerkMiddleware, requireAuth } from '@clerk/express'

app.use(clerkMiddleware())

app.get('/api/protected', requireAuth(), (req, res) => {
  res.json({
    message: 'Hello!',
    userId: req.auth.userId
  })
})

Resources

Next Steps

Proceed to clerk-local-dev-loop for local development workflow setup.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/clerk-hello-world-ms2s7cmh/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/clerk-hello-world-ms2s7cmh' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/clerk-hello-world-ms2s7cmh/download' --output '.skill-downloads/clerk-hello-world-ms2s7cmh/SKILL.md.part' && mv '.skill-downloads/clerk-hello-world-ms2s7cmh/SKILL.md.part' '.skill-downloads/clerk-hello-world-ms2s7cmh/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Read, Write, Edit, Bash(npm:*), Grep

Original excerpt: Prerequisites
  • Clerk SDK installed (clerk-install-auth completed)
  • Environment variables configured
  • ClerkProvider wrapping application

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/clerk-hello-world-ms2s7cmh/SKILL.md' && test -s '.skill-downloads/clerk-hello-world-ms2s7cmh/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/clerk-hello-world' && cp -R '.skill-downloads/clerk-hello-world-ms2s7cmh' '.claude/skills/clerk-hello-world'

Codex
test -f '.skill-downloads/clerk-hello-world-ms2s7cmh/SKILL.md' && test -s '.skill-downloads/clerk-hello-world-ms2s7cmh/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/clerk-hello-world' && cp -R '.skill-downloads/clerk-hello-world-ms2s7cmh' '.agents/skills/clerk-hello-world'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/clerk-hello-world-ms2s7cmh'

openskills read 'clerk-hello-world-ms2s7cmh'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/clerk-hello-world-ms2s7cmh/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills