diff options
author | vnugent <public@vaughnnugent.com> | 2024-03-13 16:51:14 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-03-13 16:51:14 -0400 |
commit | 92eccbf4f6784fbee7505996a97aa5bb27d12238 (patch) | |
tree | 8b367d2ed68a939962316d60cdf01e4f9d949a8d /front-end/src/store/socialMfaPlugin.ts | |
parent | 54017c76a74369700536e6ce14f575c6be0233a6 (diff) |
chore(app): just some package updates
Diffstat (limited to 'front-end/src/store/socialMfaPlugin.ts')
-rw-r--r-- | front-end/src/store/socialMfaPlugin.ts | 59 |
1 files changed, 27 insertions, 32 deletions
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<typeof useSocialOauthLogin> +type SocialMfaPlugin = ReturnType<typeof useOauthLogin> declare module 'pinia' { export interface PiniaCustomProperties { @@ -21,26 +28,16 @@ export const socialMfaPlugin = (portalEndpoint?: MaybeRef<string>): 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<SocialMfaPlugin>((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<string>): 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<SocialOAuthPortal[]>(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) }) }) |