-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
auth.api.ts
45 lines (39 loc) · 1.28 KB
/
auth.api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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"
// keeping it as string to avoid backend accidentally breaking frontend when adding new providers
providers: z.array(z.string()),
})
export const getAllowedAuthProviders = async () => {
try {
const res = await axios.get(
`${import.meta.env.VITE_BACKEND_API_URL}/auth/providers`,
{
withCredentials: true,
}
)
const parseResult = expectedAllowedProvidersSchema.safeParse(res.data)
if (!parseResult.success) {
return E.left("SOMETHING_WENT_WRONG")
}
return E.right(parseResult.data.providers)
} catch (_) {
return E.left("SOMETHING_WENT_WRONG")
}
}
export const updateUserDisplayName = (updatedDisplayName: string) =>
runMutation<
UpdateUserDisplayNameMutation,
UpdateUserDisplayNameMutationVariables,
""
>(UpdateUserDisplayNameDocument, {
updatedDisplayName,
})()