Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move user profile data from Auth0 #305

Merged
merged 6 commits into from
Jun 7, 2023
Merged

Move user profile data from Auth0 #305

merged 6 commits into from
Jun 7, 2023

Conversation

vnugent
Copy link
Contributor

@vnugent vnugent commented Jun 1, 2023

#202 part 2

  • Maintain our own user profile in the db
  • Import public-facing user profile data from Auth0
  • Create user profile Create/Read/Update GQL API
  • Create a new GQL query for user profile page
  • Add/update unit tests

Overview

  1. One-time migration job to copy user profiles (only public information) from Auth0 to Mongo
    Note: Email is considered 'private'. Currently, email is not returned from any GQL queries.
  # what to copy from Auth0
  username?: string
  userUuid: string
  displayName?: string
  bio?: string
  website?: string
  email?: string
  avatar?: string
  1. Going forward we will maintain user profile and metadata in our own DB
  2. Auth0 continues to handle authentication/password change/JWT

Migration steps (staging and prod)

New queries & mutations

Useful for getting username from uuid

query MyQuery2 {
  getUsername(input: {userUuid: "b9f8ab3b-e6e5-4467-9adb-65d91c7ebe7c"}) {
    username
    lastUpdated
    userUuid
  }
}


{
  "data": {
    "getUsername": {
      "username": "viet-test-profile1",
      "lastUpdated": 1676628726836,
      "userUuid": "b9f8ab3b-e6e5-4467-9adb-65d91c7ebe7c"
    }
  }

getUserPublicProfileByUuid() currently not being used by the frontend (yet)

query MyQuery {
  getUserPublicProfileByUuid(
    input: {userUuid: "b9f8ab3b-e6e5-4467-9adb-65d91c7ebe7c"}
  ) {
    displayName
    bio
    website
    avatar
    userUuid
    username
  }
}

{
  "data": {
    "getUserPublicProfileByUuid": {
      "displayName": "viet",
      "bio": "test profile",
      "website": "",
      "avatar": "https://s.gravatar.com/avatar/c185452daad3fe5bf7707813b1a295e8?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fvi.png",
      "userUuid": "b9f8ab3b-e6e5-4467-9adb-65d91c7ebe7c",
      "username": "viet-test-profile1"
    }
  }
}

Query for openbeta.io/u/<username> page

query MyQuery3 {
  getUserPublicPage(input: {username: "viet-test-profile1"}) {
    profile {
      website
      username
      userUuid
      displayName
      avatar
      bio
    }
    mediaList {
      id
      mediaUrl
    }
  }
}

{
  "data": {
    "getUserPublicPage": {
      "profile": {
        "website": "",
        "username": "viet-test-profile1",
        "userUuid": "b9f8ab3b-e6e5-4467-9adb-65d91c7ebe7c",
        "displayName": "viet",
        "avatar": "https://s.gravatar.com/avatar/c185452daad3fe5bf7707813b1a295e8?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fvi.png",
        "bio": "test profile"
      },
      "mediaList": [
        {
          "id": "645836e5854f76d7a9dcf76c",
          "mediaUrl": "/u/b9f8ab3b-e6e5-4467-9adb-65d91c7ebe7c/KfB8dcN6gg.jpg"
        },
        {
          "id": "645836e5854f76d7a9dcf767",
          "mediaUrl": "/u/b9f8ab3b-e6e5-4467-9adb-65d91c7ebe7c/WgMbnnP9kQ.jpeg"
        }]
    }
}

Does username exist?

Uses by the username change form to see if a username already exists

query MyQuery4 {
  usernameExists(input: {username: "newuser"})
}

{
  "data": {
    "usernameExists": true
  }
}

@vnugent vnugent changed the title Fix 202 part2 Move user profile data from Auth0 Jun 2, 2023
@vnugent vnugent marked this pull request as ready for review June 5, 2023 20:29
@vnugent vnugent requested review from zichongkao and musoke June 5, 2023 20:37
@vnugent
Copy link
Contributor Author

vnugent commented Jun 5, 2023

@zichongkao @musoke can you please have a look at this PR

Copy link
Contributor

@zichongkao zichongkao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me!

@@ -36,18 +40,34 @@ const onConnected = async (): Promise<void> => {
const userUuid = muuid.from(folderUuidStr)
const f = fs.readFileSync(file.fullpath(), 'utf-8')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully these files are comprehensive. There's a risk that users can sign up and create new Auth0 accounts while this script is being run right? I can the rate of users joining is low, and we can check after the fact that the counts match up.

Copy link
Contributor Author

@vnugent vnugent Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a risk that users can sign up and create new Auth0 accounts while this script is being run right?

For this reason I disabled new user sign up before I downloaded all user folders/image files from Sirv a couple weeks ago. There's also a new check in the frontend for all logged in users. If a logged in user is not found in the Users collection, they must select a username which will then create a new document in Users.

src/model/UserDataSource.ts Show resolved Hide resolved
Copy link
Contributor

@musoke musoke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this all looks good to me!

src/db/UserTypes.ts Show resolved Hide resolved
src/graphql/resolvers.ts Outdated Show resolved Hide resolved
src/graphql/schema/User.gql Show resolved Hide resolved
viet nguyen added 2 commits June 6, 2023 17:56
chore: revert unrelated change in area resolver
@vnugent vnugent merged commit 485120b into develop Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants