From 92eccbf4f6784fbee7505996a97aa5bb27d12238 Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 13 Mar 2024 16:51:14 -0400 Subject: chore(app): just some package updates --- front-end/src/store/socialMfaPlugin.ts | 59 ++++++++++++++++------------------ 1 file changed, 27 insertions(+), 32 deletions(-) (limited to 'front-end/src/store/socialMfaPlugin.ts') diff --git a/front-end/src/store/socialMfaPlugin.ts b/front-end/src/store/socialMfaPlugin.ts index 3968cf1..2f78f3a 100644 --- a/front-end/src/store/socialMfaPlugin.ts +++ b/front-end/src/store/socialMfaPlugin.ts @@ -1,12 +1,19 @@ import 'pinia' import { MaybeRef } from 'vue'; -import { useSocialOauthLogin, useUser, SocialOAuthPortal, fromPortals, useAxios } from '@vnuge/vnlib.browser' +import { + useUser, + useOauthLogin, + useSocialDefaultLogout, + fetchSocialPortals, + fromSocialPortals, + fromSocialConnections, +} from '@vnuge/vnlib.browser' import { get } from '@vueuse/core'; import { PiniaPluginContext, PiniaPlugin, storeToRefs } from 'pinia' import { defer } from 'lodash-es'; -type SocialMfaPlugin = ReturnType +type SocialMfaPlugin = ReturnType declare module 'pinia' { export interface PiniaCustomProperties { @@ -21,26 +28,16 @@ export const socialMfaPlugin = (portalEndpoint?: MaybeRef): PiniaPlugin const { } = storeToRefs(store) const { logout } = useUser() - /** - * Override the logout function to default to a social logout, - * if the social logout fails, then we will logout the user - */ - const setLogoutMethod = (socialOauth: SocialMfaPlugin) => { - const logoutFunc = socialOauth.logout; - - (socialOauth as any).logout = async () => { - if (await logoutFunc() === false) { - await logout() - } - } - } + //Create social login from available portals + const defaultSocial = useSocialDefaultLogout( + useOauthLogin([]), + logout //fallback to default logout + ); const _loadPromise = new Promise((resolve, _) => { if (get(portalEndpoint) == null) { - const socialOauth = useSocialOauthLogin([]) - setLogoutMethod(socialOauth) - return resolve(socialOauth) + return resolve(defaultSocial) } /* @@ -50,27 +47,25 @@ export const socialMfaPlugin = (portalEndpoint?: MaybeRef): PiniaPlugin defer(async () => { - let portals: SocialOAuthPortal[] = [] - try { - //Get axios instance - const axios = useAxios(null) + + const portals = await fetchSocialPortals(get(portalEndpoint)!); + const social = fromSocialPortals(portals); + const methods = fromSocialConnections(social); - //Get all enabled portals - const { data, headers } = await axios.get(get(portalEndpoint)!); + //Create social login from available portals + const login = useOauthLogin(methods); - if(headers['content-type'] === 'application/json') { - portals = data - } + const socialOauth = useSocialDefaultLogout(login, logout); + + console.log(login.methods) + + resolve(socialOauth) } catch (error) { //Let failure fall back to default + resolve(defaultSocial) } - - //Create social login from available portals - const socialOauth = useSocialOauthLogin(fromPortals(portals)); - setLogoutMethod(socialOauth); - resolve(socialOauth) }) }) -- cgit