Is there a way to "pass" the user.name of auth0 user to a async function?

59 Views Asked by At

I'm creating a next.js app which reads a custom post type from a wordpress multisite. I want when a user sign-in (using auth0), the name of the user to go in the wordpress URL to replace the "site" name.

For example: I have this code in utils/wordpress.js

const BASE_URL = "https://fsm.xristosavgeros.com/sitename/wp-json/wp/v2/work";

export async function getPosts() {
  const postsRes = await fetch(BASE_URL + "?_embed");
  const posts = await postsRes.json();
  const filterPosts = posts.filter((post) => post.assigned_to == 'Johnny Worker');
  return filterPosts;
  }

What I need is something like this:

const BASE_URL = "https://fsm.xristosavgeros.com/ + user.name + /wp-json/wp/v2/work";

I think the way to go is useUser() hook but no matter where i tried to use it, the app crashes.

Any ideas?

0

There are 0 best solutions below