aboutsummaryrefslogtreecommitdiff
path: root/front-end/src/store/socialMfaPlugin.ts
blob: d328399f25ac9e562e79df4542ad8bd988f010bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

import 'pinia'
import {  } from 'vue';
import { useSocialOauthLogin, createSocialMethod, useUser } from '@vnuge/vnlib.browser'
import {  } from '@vueuse/core';
import { PiniaPluginContext, PiniaPlugin, storeToRefs } from 'pinia'
import {  } from 'lodash-es';

declare module 'pinia' {
    export interface PiniaCustomProperties {
        socialOauth: ReturnType<typeof useSocialOauthLogin>
    }
}

export const socialMfaPlugin: PiniaPlugin = ({ store }: PiniaPluginContext) => {

    const { } = storeToRefs(store)
    const { logout } = useUser()

    //Setup social providers
    const socialOauth = useSocialOauthLogin([
        //createSocialMethod('github', '/login/social/github'),
        //createSocialMethod('discord', '/login/social/discord'),
    ])

    /**
     * Override the logout function to default to a social logout,
     * if the social logout fails, then we will logout the user
     */

    const logoutFunc = socialOauth.logout;

    (socialOauth as any).logout = async () => {
        if (await logoutFunc() === false) {
            await logout()
        }
    }

    return {
        socialOauth
    }
}