Skip to content

How to get cookies in createResource with "use server"? #1596

Closed Answered by qhj
qhj asked this question in Q&A
Discussion options

You must be logged in to vote

Solved.

import { createResource } from "solid-js";
import { getRequestEvent } from "solid-js/web";

export default function Home() {
  const [test] = createResource(async () => {
    return (
      await fetch("http://localhost:3000/api/test", {
        headers: getRequestEvent()?.request.headers,
      })
    ).text();
  });

  return (
    <>
      <div>{test()}</div>
    </>
  );
}

My acturally question is how to getting cookies in trpc querying issued in ssr phase:

import { createTRPCClient, httpBatchLink } from "@trpc/client";
import type { AppRouter } from "./router";
import { getRequestEvent } from "solid-js/web";

export const trpc = createTRPCClient<AppRouter>({
  links: [
    ht…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by qhj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant