#NextJS revalidate path with supabase

26 messages ยท Page 1 of 1 (latest)

hybrid coral
#

Am i missing something or i did something wrong? So in my explore page there's a profile card that use the user username. and the page only update the value when i refresh the page

export async function usernameChange({ username }: usernameChangeSchema) {
  // Username Update
  revalidatePath('/explore', 'page');
  return { data };
}

And this is my explore page

export default async function ExplorePage() {
  const users = await getCreators();
return(
//Explore Page
)
export async function getCreators() {
  const supabase = createServerClient();
  try {
    const { data, error } = await supabase
      .from('user_profiles')
      .select('*')

    if (!data) {
      throw error;
    }

    return data;
  } catch (error) {
    console.error('Error:', error);
    throw error;
  }
}
sudden fernBOT
#

๐Ÿ”Ž This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

๐Ÿ•ต๏ธ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

โœ… You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

green raft
hybrid coral
#

one thing i found is if we use
revalidatePath('/', 'layout')
it will work, but not any other else, but this will revalidate everything which i do not want

green raft
#

I thought that was in the example project?

#

Strange, still dosnt work for me.

hybrid coral
#

Which example project can you link it here?

green raft
#

npx create-next-app -e with-supabase

hybrid coral
#

Hmm idk if it is okay to tag some mod / helper

#

I actually cant find that they used revalidatePath in the example project

hybrid coral
safe harness
hybrid coral
safe harness
hybrid coral
#

Both of the questions above is no, for the questions above before i added the try / catch

#

๐Ÿ˜–

#

Looking into this, giving me a try to add try / catch block for my function

Redirecting
If you would like to redirect the user to a different route after the completion of a Server Action, you can use redirect API. redirect needs to be called outside of the try/catch block:

https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#redirecting

Learn how to handle form submissions and data mutations with Next.js.

safe harness
#

redirect needs to be called outside try/catch but revalidatePath needs not be called that way thinkies

hybrid coral
#

oh okay, that's weird ๐Ÿค”

safe harness
#

well, if it works it works

hybrid coral
#

So why does it only works when i put it inside try / catch ๐Ÿ˜‚

#

Yeah, thanks!

#

Hey @green raft you might want to try wrapping your function inside of try/catch