mirror of
https://github.com/YunoHost/yunohost-portal.git
synced 2024-09-03 20:06:23 +02:00
handle 401 depending on settings.public and route.meta.public
This commit is contained in:
parent
5286b22dd2
commit
d39440c3bc
4 changed files with 19 additions and 5 deletions
|
@ -38,11 +38,15 @@ export function useApi<T>(
|
|||
.then((data) => {
|
||||
result.data.value = data as T
|
||||
})
|
||||
.catch((e: FetchError) => {
|
||||
.catch(async (e: FetchError) => {
|
||||
result.error.value = e
|
||||
if (e.statusCode === 401) {
|
||||
useIsLoggedIn().value = false
|
||||
navigateTo('/login')
|
||||
const route = useRoute()
|
||||
const settings = await useSettings()
|
||||
if (!(settings.value.public && route.meta.public)) {
|
||||
navigateTo('/login')
|
||||
}
|
||||
} else if (e.statusCode !== 400 && !e.data?.path) {
|
||||
throw createError({
|
||||
statusCode: e.statusCode,
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import { useIsLoggedIn, useRedirectUrl } from '@/composables/states'
|
||||
import {
|
||||
useIsLoggedIn,
|
||||
useRedirectUrl,
|
||||
useSettings,
|
||||
} from '@/composables/states'
|
||||
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const isLoggedIn = useIsLoggedIn()
|
||||
const settings = await useSettings()
|
||||
|
||||
useRedirectUrl().value = (from.query.r as string) || null
|
||||
if (useRedirectUrl().value && to.name === 'login') {
|
||||
|
@ -11,7 +16,7 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
|||
if (to.name === 'login' && isLoggedIn.value) {
|
||||
return navigateTo('/')
|
||||
}
|
||||
if (to.name !== 'login' && !isLoggedIn.value) {
|
||||
if (!isLoggedIn.value && !(to.meta.public && settings.value.public)) {
|
||||
return navigateTo('/login')
|
||||
}
|
||||
})
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
const { t } = useI18n()
|
||||
const appsData = await useApps()
|
||||
|
||||
definePageMeta({
|
||||
public: true,
|
||||
})
|
||||
|
||||
const apps = computed(() => {
|
||||
const appTileColors = [
|
||||
['bg-primary', 'text-primary-content'],
|
||||
|
|
|
@ -5,6 +5,7 @@ import * as yup from 'yup'
|
|||
|
||||
definePageMeta({
|
||||
layout: false,
|
||||
public: true,
|
||||
})
|
||||
|
||||
const { t } = useI18n()
|
||||
|
|
Loading…
Add table
Reference in a new issue