Hello community,
I’m developing an web app and found a bottleneck in my app related to api calls today.
I’m retrieving my app data from mongodb server through find() operation in next js app and found that it works perfectly fine when run in development mode but when I deployed my application and tried to retrieve data through https:// promptopia-theta-swart.vercel.app/api/prompt , its returning outdated data each and every time and I had searched all over internet but can’t find any suitable answers for that.
please help me out!
env variables you have to setup are for :
->GOOGLE_ID
->GOOGLE_SECRET
->MONGODB_URI
->NEXTAUTH_URL
->NEXTAUTH_URL_INTERNAL
->NEXTAUTH_SECRET
in .env file
steps to get these are:
- google cloud console project at https://cloud.google.com/ .
→ setup new project
→ create oauth consent screen
→ put http:// localhost:3000 in oauth url
→ create credentials
→ add http:// localhost:3000 to “Authorised JavaScript origins”
→ add http:// localhost:3000 and http:// localhost:3000/api/auth/callback/google to “Authorised redirect URIs”
→ copy [ GOOGLE_ID, GOOGLE_SECRET] named in website as client id and client secret - mongodb database uri [MONGODB_URI]
→ mongodb+srv://username:password@(database name).mongodb.net/?retryWrites=true&w=majority
→ or get it from mongodb site via connect → drivers → nodejs - next auth →
a. NEXTAUTH_URL = http:// localhost:3000
b. NEXTAUTH_URL_INTERNAL = http:// localhost:3000
c. NEXTAUTH_SECRET = anything you want to put without spaces
if you set it up …you will find no issue in development phase i.e. while you are running it in localhost …when you host it on vercel (its perfect hosting platform for next js apps and really easy to upload and running in no time) then you will notice the issue here
the big one is showing 2 prompts in database
and the one in middle showing only 1 single prompt in website
i have tried creating several prompts … but to no effect… it fetches updated data in localhost and outdated data in website : https:// promptopia-theta-swart.vercel.app/api/prompt
notice:
if you decide to host it on vercel just follow these steps:
→ upload your project on github
→ login with same github account in vercel
→ create new app
→ select repo
→ set env variables manually (scroll down a bit and you will find the place to add them)
→ deploy
→ go to google cloud console and add your web app link in credentials → Authorised JavaScript origins and Authorised redirect URIs with same follow ups ahead of them as localhost (this step is required for google login)
→ update nextauth with new link in your env variables as well
and at last please find the solution to this issue… its so annoying