tierrun / tier-vercel-openai

This project generates marketing content using OpenAI, implements metered pricing model, checks for feature access based on their current subscription, reports usage of a feature, manages subscription and more using Tier.
https://tier-vercel-openai.vercel.app
MIT License
339 stars 50 forks source link

All history is visible #3

Closed toddcooke closed 1 year ago

toddcooke commented 1 year ago

Describe the bug I am able to see many generated marketing copies, going back months, rather than the 1 I created.

To Reproduce Steps to reproduce the behavior:

I'm not positive about how to reproduce, but it seems like immediately after a refresh only my one copy is visible, but after waking my machine from sleep more (all?) are visible

Expected behavior I expect to only be able to view the copy I created, in my case just the one.

Screenshots If applicable, add screenshots to help explain your problem.

https://imgur.com/IuECfKZ

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

jerriclynsjohn commented 1 year ago

This shouldn't happen at all. I'm querying based on the logged-in user's specific UserID. I'm trying to reproduce the bug and I'm with no luck. Please share the network call details using tools like jam.dev I'm at jerric@tier.run, it would really help me debug this issue.

jerriclynsjohn commented 1 year ago

I've pushed a small check, let me know if that resolves. But I'm so sure that's not the case

toddcooke commented 1 year ago

I had the problem while using Firefox but I can record with Chrome just in case. Here is a recording using chrome https://jam.dev/c/3b236de0-c7bc-40cd-825c-cdfeb20eb774

I've also cleared my cookies with Firefox then recorded the network activity as a HAR file. https://drive.google.com/file/d/17peJbYEXPrVaUpF6Zyx5OPR2d9Q2lPi1/view?usp=sharing You can use this to view it. http://janodvarko.cz/har/viewer/

I didn't see the problem again, but it seems difficult to reproduce. I'll keep persisting my Firefox network logs just in case.

toddcooke commented 1 year ago

Not sure if it's the issue, but you are calling getServerSession() from a component. I think that method is intended for api routes, from components you can use getSession(). https://github.com/tierrun/tier-vercel-openai/blob/b1f25bfd0e4514c2b06168595eef676e6f538456/src/lib/session.ts https://next-auth.js.org/configuration/nextjs#getserversession

jerriclynsjohn commented 1 year ago

Not sure if it's the issue, but you are calling getServerSession() from a component. I think that method is intended for api routes, from components you can use getSession(). https://github.com/tierrun/tier-vercel-openai/blob/b1f25bfd0e4514c2b06168595eef676e6f538456/src/lib/session.ts https://next-auth.js.org/configuration/nextjs#getserversession

This shouldn't be the issue as this page is inherently SSR and we do not have any components with use client. So accessing server stuff here shouldn't be a problem. I'm thinking maybe Prisma broke momentarily and fetched all the data from DB, we are filtering based on userId. This is the only thing that I can think of as of now.

jerriclynsjohn commented 1 year ago

@toddcooke Thanks a lot for pointing me in this direction, apparently, this was a Prisma issue that it will return everything from the table if the filter param is undefined.

See related issues @ Prisma #20169 #8231

I've fixed this by adding a check.