diff options
author | vnugent <public@vaughnnugent.com> | 2024-01-30 15:23:06 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-01-30 15:23:06 -0500 |
commit | 5abc489b9954111d66d1385aa62a3ea962fa0a55 (patch) | |
tree | b1715e5c5e6316f33e3e33fb55397d93200ab518 /front-end/src/store/userProfile.ts | |
parent | e4dc63ded324c6e9678603296953bb1f7dea7569 (diff) |
merge upstream. Add dynamic client-side support for optional oauth2 and social login methods
Diffstat (limited to 'front-end/src/store/userProfile.ts')
-rw-r--r-- | front-end/src/store/userProfile.ts | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/front-end/src/store/userProfile.ts b/front-end/src/store/userProfile.ts index a4ea469..0320ace 100644 --- a/front-end/src/store/userProfile.ts +++ b/front-end/src/store/userProfile.ts @@ -3,7 +3,8 @@ import { MaybeRef, watch } from 'vue'; import { ServerDataBuffer, ServerObjectBuffer, UserProfile, WebMessage, apiCall, useAxios, useDataBuffer, useUser } from '@vnuge/vnlib.browser'; import { get, useToggle } from '@vueuse/core'; import { PiniaPlugin, PiniaPluginContext, storeToRefs } from 'pinia' -import { defer } from 'lodash-es'; +import { defer, noop } from 'lodash-es'; +import { storeExport } from './index'; export interface OAuth2Application { readonly Id: string, @@ -24,17 +25,21 @@ interface ExUserProfile extends UserProfile { created: string | Date } +export interface UserProfileStore{ + userProfile: ServerDataBuffer<ExUserProfile, WebMessage<string>> + userName: string | undefined + refreshProfile(): void; +} + declare module 'pinia' { - export interface PiniaCustomProperties { - userProfile: ServerDataBuffer<ExUserProfile, WebMessage<string>> - userName: string | undefined - refreshProfile(): void; + export interface PiniaCustomProperties extends UserProfileStore { + } } export const profilePlugin = (accountsUrl:MaybeRef<string>) :PiniaPlugin => { - return ({ store }: PiniaPluginContext) => { + return ({ store }: PiniaPluginContext): UserProfileStore => { const { loggedIn } = storeToRefs(store) const { getProfile, userName } = useUser() @@ -64,19 +69,16 @@ export const profilePlugin = (accountsUrl:MaybeRef<string>) :PiniaPlugin => { userProfile.apply(profile) } - watch([loggedIn, onRefresh], ([li]) => { - //If the user is logged in, load the profile buffer - if (li) { - apiCall(loadProfile) - } - }) + //If the user is logged in, load the profile buffer + watch([loggedIn, onRefresh], ([li]) => li ? apiCall(loadProfile) : noop()) + //Defer intiial profile load defer(refreshProfile); - return { + return storeExport({ userProfile, refreshProfile, userName - } + }) } }
\ No newline at end of file |