aboutsummaryrefslogtreecommitdiff
path: root/front-end/src/store/socialMfaPlugin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'front-end/src/store/socialMfaPlugin.ts')
-rw-r--r--front-end/src/store/socialMfaPlugin.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/front-end/src/store/socialMfaPlugin.ts b/front-end/src/store/socialMfaPlugin.ts
new file mode 100644
index 0000000..d328399
--- /dev/null
+++ b/front-end/src/store/socialMfaPlugin.ts
@@ -0,0 +1,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
+ }
+} \ No newline at end of file