Next.js Discord

Discord Forum

Disabling cache for 3rd party requests

Answered
Dwarf Crocodile posted this in #help-forum
Open in Discord
Dwarf CrocodileOP
How can I disable nextjs from caching this Cognito request?

this is what my component looks like:

"use client" async function onSubmit(data: CreateNewAccountSchema) { try { await register("id", data.email, data.name, data.password) toast({ title: "", description: "", }) } catch (error) { console.log(error) } }


and the server action:

"use server" export async function register( id: string, email: string, name: string, password: string ) { const request = new Promise((resolve, reject) => { const attributes = [ new CognitoUserAttribute({ Name: "email", Value: email }), new CognitoUserAttribute({ Name: "name", Value: name }), ] const validations: CognitoUserAttribute[] = [] userPool().signUp(id, password, attributes, validations, (err, result) => err ? reject(err) : resolve(result) ) }) const response = (await request) as ISignUpResult }
Answered by Spectacled bear
I think only requests made using the fetch api are cached by default, so you should be good on that. However, the page produced as a result of making the call will likely be cached. To prevent this, you'll need to set
export const revalidate = 0
on the UI route that contains this server action (probably the nearest server component above it)
View full answer

6 Replies

Spectacled bear
I think only requests made using the fetch api are cached by default, so you should be good on that. However, the page produced as a result of making the call will likely be cached. To prevent this, you'll need to set
export const revalidate = 0
on the UI route that contains this server action (probably the nearest server component above it)
Answer
Dwarf CrocodileOP
the cognito request is being cached, you can se in the print I provided

is this NextJs or AWS SDK?
Spectacled bear
Did you try the revalidate = 0 I suggested?
Dwarf CrocodileOP
I did now, thank you VERY MUCH. This fixes the issue
How do I mark this as answered?
Spectacled bear
If you scroll up to the auto generated reply that was the first reply to your question, it tells you. And you're welcome