Welcome to your new app

Sign up for an account to get started

API request example

ResponseYou are signed out, so the request will return null

// Click above to run the request

pages/api/getAuthenticatedUserId.js

import { withAuth } from "@clerk/nextjs/api";

export default withAuth((req, res) => {
  const { sessionId } = req.auth;

  if (!sessionId) {
    return res.status(401).json({ id: null });
  }

  return res.status(200).json({ id: sessionId });
});