feat: dynamically load enabled auth providers (#3646)
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user