feat: added mutation and function to platform for updating user profile name (#3929)

Co-authored-by: amk-dev <akash.k.mohan98@gmail.com>
Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
This commit is contained in:
Nivedin
2024-03-25 14:41:25 +05:30
committed by GitHub
parent 1113c79e20
commit c326f54f7e
7 changed files with 68 additions and 18 deletions

View File

@@ -1,6 +1,12 @@
import { runMutation } from "@hoppscotch/common/helpers/backend/GQLClient"
import axios from "axios"
import * as E from "fp-ts/Either"
import { z } from "zod"
import {
UpdateUserDisplayNameDocument,
UpdateUserDisplayNameMutation,
UpdateUserDisplayNameMutationVariables,
} from "../../api/generated/graphql"
const expectedAllowedProvidersSchema = z.object({
// currently supported values are "GOOGLE", "GITHUB", "EMAIL", "MICROSOFT", "SAML"
@@ -28,3 +34,12 @@ export const getAllowedAuthProviders = async () => {
return E.left("SOMETHING_WENT_WRONG")
}
}
export const updateUserDisplayName = (updatedDisplayName: string) =>
runMutation<
UpdateUserDisplayNameMutation,
UpdateUserDisplayNameMutationVariables,
""
>(UpdateUserDisplayNameDocument, {
updatedDisplayName,
})()

View File

@@ -8,7 +8,8 @@ import { PersistenceService } from "@hoppscotch/common/services/persistence"
import axios from "axios"
import { BehaviorSubject, Subject } from "rxjs"
import { Ref, ref, watch } from "vue"
import { getAllowedAuthProviders } from "./auth.api"
import { getAllowedAuthProviders, updateUserDisplayName } from "./auth.api"
import * as E from "fp-ts/Either"
export const authEvents$ = new Subject<AuthEvent | { event: "token_refresh" }>()
const currentUser$ = new BehaviorSubject<HoppUser | null>(null)
@@ -317,9 +318,22 @@ export const def: AuthPlatformDef = {
async setEmailAddress(_email: string) {
return
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setDisplayName(name: string) {
return
if (!name) return E.left("USER_NAME_CANNOT_BE_EMPTY")
if (!currentUser$.value) return E.left("NO_USER_LOGGED_IN")
const res = await updateUserDisplayName(name)
if (E.isRight(res)) {
setUser({
...currentUser$.value,
displayName: res.right.updateDisplayName.displayName ?? null,
})
return E.right(undefined)
}
return E.left(res.left)
},
async signOutUser() {