Skip to content

Commit dca3d57

Browse files
committed
chore: remove redundant store
1 parent 7f2a227 commit dca3d57

36 files changed

+1030
-1432
lines changed

app/@layouts/components/NavbarShortcuts.vue

Lines changed: 0 additions & 41 deletions
This file was deleted.

app/@layouts/components/UserProfile.vue

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
44
55
const { t } = useI18n()
66
const authStore = useAuthStore()
7-
const tokenDeviceStore = useTokenDeviceStore()
8-
const userEmail = computed(() => authStore.currentUser?.email)
9-
const userAvatar = computed(() => authStore.currentUser?.picture)
7+
const userEmail = computed(() => authStore.currentUser?.primary_email)
8+
const userAvatar = computed(() => authStore.currentUser?.avatar)
109
const userFullname = computed(() => authStore.currentUser?.name)
11-
const userRole = computed(() => authStore.currentUser?.roles?.[0] || authStore.currentUser?.organization_roles?.[0] || t('User'))
1210
1311
async function logout() {
1412
try {
15-
if (authStore.currentUser)
16-
await tokenDeviceStore.clearTokenDevice()
17-
18-
await authStore.signOut()
13+
await navigateTo({ path: '/sign-out' }, { external: true })
1914
2015
navigateTo({ name: 'auth-login' })
2116
}
@@ -51,12 +46,12 @@ const userProfileList = computed<Array<{
5146
title: t('Pricing'),
5247
to: { name: 'settings-pricing' },
5348
},
54-
{
55-
type: 'navItem',
56-
icon: 'ri-question-line',
57-
title: 'FAQ',
58-
to: { name: 'faq' },
59-
},
49+
// {
50+
// type: 'navItem',
51+
// icon: 'ri-question-line',
52+
// title: 'FAQ',
53+
// to: { name: 'faq' },
54+
// },
6055
])
6156
</script>
6257

@@ -114,8 +109,8 @@ const userProfileList = computed<Array<{
114109
<div class="text-body-2 font-weight-medium text-high-emphasis">
115110
{{ userFullname || userEmail }}
116111
</div>
117-
<div class="text-capitalize text-caption text-disabled">
118-
{{ userRole }}
112+
<div class="text-caption text-disabled">
113+
{{ userEmail }}
119114
</div>
120115
</div>
121116
</div>

app/@layouts/components/layout/DefaultLayoutWithHorizontalNav.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ const config = useRuntimeConfig()
3030
<NavBarI18n />
3131

3232
<NavbarThemeSwitcher />
33-
<NavbarShortcuts />
34-
<NavBarNotifications class="me-2" />
33+
<!-- <NavBarNotifications class="me-2" /> -->
3534
<UserProfile />
3635
</template>
3736

app/@layouts/components/layout/DefaultLayoutWithVerticalNav.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ watch([
3939

4040
<NavBarI18n />
4141
<NavbarThemeSwitcher />
42-
<NavbarShortcuts />
43-
<NavBarNotifications class="me-2" />
42+
<!-- <NavBarNotifications class="me-2" /> -->
4443
<UserProfile />
4544
</div>
4645
</template>

app/api/auth.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
import type { User } from '@base/server/types/models'
2+
13
export function useApiAuth() {
4+
function fetchProfile() {
5+
// Get user credit from our database instead of depending on Logto data
6+
return $api<{ data: User }>('/api/auth/me')
7+
}
8+
29
function updateProfile(payload: Partial<{ username: string, name: string, avatar: string }>) {
310
return $api('/api/auth/me', {
411
method: 'PATCH',
@@ -14,6 +21,7 @@ export function useApiAuth() {
1421
}
1522

1623
return {
24+
fetchProfile,
1725
updateProfile,
1826
updatePassword,
1927
}

app/app.vue

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { useTheme } from 'vuetify'
3-
import { getMessaging, onMessage } from 'firebase/messaging'
3+
import { getMessaging, getToken } from 'firebase/messaging'
44
import ScrollToTop from '@base/@core/components/ScrollToTop.vue'
55
import initCore from '@base/@core/initCore'
66
import { initConfigStore, useConfigStore } from '@base/@core/stores/config'
@@ -18,14 +18,29 @@ const { global } = useTheme()
1818
if (isMobile)
1919
configStore.appContentLayoutNav = 'vertical'
2020
21-
onBeforeMount(async () => {
22-
if (!isInAppBrowser()) {
23-
onMessage(getMessaging(), () => {
24-
// TODO: Handle incoming messages
25-
// console.log('Client message:', payload)
26-
// const linkSplits = payload.fcmOptions?.link?.split('/projects/')
27-
// notify(payload.notification?.body as string, { type: 'primary', link: `/projects/${linkSplits![1]}` })
28-
})
21+
const config = useRuntimeConfig()
22+
23+
const tokenDevice = useLocalStorage<string | null>('tokenDevice', null)
24+
25+
const notificationApi = useApiNotification()
26+
27+
onMounted(async () => {
28+
if (!isInAppBrowser() && !tokenDevice.value) {
29+
try {
30+
if (Notification.permission !== 'granted')
31+
await Notification.requestPermission()
32+
33+
const authStore = useAuthStore()
34+
35+
whenever(() => authStore.currentUser, async (currentUser) => {
36+
if (Notification.permission === 'granted' && currentUser) {
37+
const token = await getToken(getMessaging(), { vapidKey: config.public.firebase.keyPair })
38+
39+
notificationApi.createTokenDevice(token)
40+
}
41+
})
42+
}
43+
catch {}
2944
}
3045
})
3146
</script>

app/components/account-settings/AccountSettingsAccount.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const config = useRuntimeConfig()
55
66
const inputFileRef = ref<HTMLElement>()
77
8+
const authApi = useApiAuth()
9+
810
const authStore = useAuthStore()
911
const formFile = ref<File | null>(null)
1012
@@ -97,7 +99,7 @@ async function handleSubmit() {
9799
if (formFile.value && authStore.currentUser)
98100
avatarUrl = await uploadToS3(formFile.value, authStore.currentUser.sub)
99101
100-
await authStore.updateProfile({
102+
await authApi.updateProfile({
101103
...formData.value,
102104
avatar: avatarUrl,
103105
})

app/composables/useMessaging.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/error.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defineProps<{
1212

1313
<template>
1414
<ErrorNotFound v-if="error?.statusCode === 404" />
15-
<ErrorUnauthorized v-if="error?.statusCode === 403" />
15+
<ErrorUnauthorized v-if="error?.statusCode === 403 || error?.statusCode === 401" />
1616
<ErrorUnderMaintenance v-if="error?.statusCode === 503" />
1717
<ErrorInternalServerError v-else :error="error" />
1818
</template>

app/middleware/01.health.global.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ export default defineNuxtRouteMiddleware(async (to) => {
22
if (to.meta.public || import.meta.prerender)
33
return
44

5-
const healthStore = useHealthStore()
6-
75
try {
8-
await healthStore.fetchHealthCheck()
6+
await useApiHealth().fetchHealthCheck()
97
}
108
catch {
119
throw createError({

0 commit comments

Comments
 (0)