Auth0 get user info in getCurrentUser

decoded doesnt have anything like name or email which I’m trying to get.

What I am trying to do is whenever you login with Auth0, create a user in the db if one does not exists with a specific id (functionality for this is done). Then populate the user with generic info like name, email, picture, etc.

All of the data exists in userMetadata but I can’t find a way to access that here.

export const getCurrentUser = async (
  decoded: Decoded
): Promise<RedwoodUser | null> => {
  if (!decoded) {
    return null
  }
  const user = await db.user.findUnique({
    where: {
      auth0id: decoded.sub,
    },
  })
  // console.log({ email })
  if (user) {
    console.log('returning existing user')
    return { ...decoded, ...user }
  } else {
    const newUser = await createUser(decoded)

    console.log('returning new user')
    return { ...decoded, ...newUser }
  }
}

const createUser = async (data) => {
  return db.user.create({
    data: {
      auth0id: data.sub,
      name: data.name,
      email: data.email,
      picture: data.picture,
    },
  })
}

The actual creation of a user works, it’s just the lack of data.