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")
}
}

View File

@@ -8,6 +8,7 @@ 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"
export const authEvents$ = new Subject<AuthEvent | { event: "token_refresh" }>()
const currentUser$ = new BehaviorSubject<HoppUser | null>(null)
@@ -341,4 +342,5 @@ export const def: AuthPlatformDef = {
window.location.href = "/"
}
},
getAllowedAuthProviders,
}

View File

@@ -1,4 +1,4 @@
import { authEvents$, def as platformAuth } from "@platform/auth"
import { authEvents$, def as platformAuth } from "@platform/auth/auth.platform"
import { CollectionsPlatformDef } from "@hoppscotch/common/platform/collections"
import { runDispatchWithOutSyncing } from "../../lib/sync"

View File

@@ -1,4 +1,4 @@
import { authEvents$, def as platformAuth } from "@platform/auth"
import { authEvents$, def as platformAuth } from "@platform/auth/auth.platform"
import {
createEnvironment,
deleteEnvironment,

View File

@@ -1,4 +1,4 @@
import { authEvents$, def as platformAuth } from "@platform/auth"
import { authEvents$, def as platformAuth } from "@platform/auth/auth.platform"
import {
restHistoryStore,
RESTHistoryEntry,

View File

@@ -1,6 +1,6 @@
import { SettingsPlatformDef } from "@hoppscotch/common/platform/settings"
import { settingsSyncer } from "./settings.sync"
import { authEvents$, def as platformAuth } from "@platform/auth"
import { authEvents$, def as platformAuth } from "@platform/auth/auth.platform"
import {
createUserSettings,
getUserSettings,

View File

@@ -2,7 +2,7 @@ import { PersistableTabState } from "@hoppscotch/common/services/tab"
import { HoppRESTDocument } from "@hoppscotch/common/helpers/rest/document"
import { HoppUser } from "@hoppscotch/common/platform/auth"
import { TabStatePlatformDef } from "@hoppscotch/common/platform/tab"
import { def as platformAuth } from "@platform/auth"
import { def as platformAuth } from "@platform/auth/auth.platform"
import { getCurrentRestSession, updateUserSession } from "./tabState.api"
import { SessionType } from "../../api/generated/graphql"
import * as E from "fp-ts/Either"