feat: dynamically load enabled auth providers (#3646)

This commit is contained in:
Akash K
2023-12-13 23:38:21 +05:30
committed by GitHub
parent 47e009267b
commit 5209c0a8ca
14 changed files with 159 additions and 103 deletions

View File

@@ -0,0 +1,30 @@
import axios from "axios"
import * as E from "fp-ts/Either"
import { z } from "zod"
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")
}
}