vercel / vercel/next.js

Docs: Access Search Param (or raw request URL) from server action

Open
#72,136 3 comments 0 reactions 1 assignee View on GitHub

@icyJoseph is already working on this.

Since Jul 13, 2026.

Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

What is the documentation issue?

In a server action, I want to access the search param directly from a server action.

I know I can progressively enhance my form with a client component like this:

"use client";

import { useEffect, useState } from "react";

// This could be loaded on the server, but that would require making this route be dynamically loaded.
// I want it to be statically loaded, so I'm okay with this callback functionality to be missing if the
// browser hasn't yet loaded JS and they submit.
export function CallbackUrlHiddenInput() {
  const [callbackUrl, setCallbackUrl] = useState("");
  useEffect(() => {
    // Check if window is defined (i.e., we're in the browser)
    if (typeof window !== "undefined") {
      const params = new URLSearchParams(window.location.search);
      const url = params.get("callbackUrl");

      if (url) {
        setCallbackUrl(url);
      }
    }
  }, []);
  return <input type="hidden" name="callbackUrl" value={callbackUrl} />;
}

However, I know that under the hood, server actions are just POST requests that have the entire request:

curl 'http://localhost:3000/sign-in?callbackUrl=http%3A%2F%2Flocalhost%3A3000%2Fadmin

It would be nice if I could grab the searchParams using something and then I could redirect the user to the correct place.

Is there a function that I could call to get direct access to the request?

Something like cookies(), but I need to access searchParams

Is there any context that might help us understand?

I am building a sign-in page and I want the form on the page to be submittable without needing to hydrate react before it will properly load the search Parameters.

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#cookies

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.