t3-oss / create-t3-app

The best way to start a full-stack, typesafe Next.js app
https://create.t3.gg
MIT License
25.4k stars 1.16k forks source link

bug: protected routes pending forever when trying to access context #1549

Closed kseikyo closed 1 year ago

kseikyo commented 1 year ago

Provide environment information

System: OS: macOS 13.4.1 CPU: (8) arm64 Apple M1 Memory: 108.92 MB / 8.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.17.1 - ~/Library/Caches/fnm_multishells/51275_1693072071250/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v18.12.0/bin/yarn npm: 8.15.0 - ~/Library/Caches/fnm_multishells/51275_1693072071250/bin/npm pnpm: 8.6.12 - ~/Library/pnpm/pnpm

"ct3aMetadata": { "initVersion": "7.19.0" }

Describe the bug

I've tried many different ways, browsers, clearing cache, flushing dns, etc. And I can reproduce even on a brand new t3 app. I'm not sure if this is a trpc or next-auth issue, so I'm sending it here.

When trying to run a query or mutation using the protectedProcedure and trying to access the context, the request stays pending until timeout, and a few session requests show up and also stay pending.

I'm using the GoogleProvider, haven't tested with other providers.

Reproduction repo

tbd

To reproduce

  1. pnpm create t3-app@latest
  2. pnpm prisma db push
  3. add GoogleProvider with working credentials
  4. Include the following code on the example router:
    // can use a query with the enabled flag too
    test: protectedProcedure.mutation(({ ctx }) => {
    console.log("ctx", ctx);
    console.log("test");
    return { data: ctx.session.user, status: 200 };
    }),
  5. Add it to the AuthShowcase component
    const { data: test, mutate } = api.example.test.useMutation();
    ...
    <button onClick={() => mutate()}>mutate</button>
  6. Sign in
  7. Click on mutate button
  8. Check devtools for pending requests

Additional information

image

c-ehrlich commented 1 year ago

This isn't related to the specifics of your setup - logging ctx.prisma will cause this, and there isn't really anything we can do about it as it's not specific to Create T3 App or tRPC.

mittalsam98 commented 9 months ago

Hey @kseikyo I am also facing same issue, how did you fix it?