Thin wrappers around Clerk server SDK to expose auth session data and current user in a consistent shape for server‑side code.
// Source: https://github.com/mperkins0155/llms-txt-hub | License: MIT | Copyright 2025 David Dias
// Provided via justclaw.it.com; keep this notice with the code.
'use server'
import 'server-only'
import { auth as clerkAuth, currentUser as clerkCurrentUser } from '@clerk/nextjs/server'
import type { AuthUser } from '../core/types'
/**
* Return the current authenticated session or null
*/
export async function auth() {
const { userId } = await clerkAuth()
if (!userId) {
return null
}
const user = await clerkCurrentUser()
if (!user) {
return null
}
// Return session-like object for compatibility
return {
user: {
id: user.id,
email: user.primaryEmailAddress?.emailAddress || null,
user_metadata: {
user_name: user.username || null,
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key