Skip to content

Commit 4216356

Browse files
committed
fix: use middleware
1 parent bb56e10 commit 4216356

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

app/app.vue

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<script setup lang="ts">
22
import hexRgb from 'hex-rgb'
33
4-
import { allowedRepos, isAllowedRepo } from '#shared/repos'
4+
import { allowedRepos } from '#shared/repos'
55
66
const route = useRoute()
7-
const selectedRepo = computed(() => {
8-
const query = route.query.repo as string | undefined
9-
return query && isAllowedRepo(query) ? query : 'nuxt/nuxt'
10-
})
7+
const selectedRepo = computed(() => route.query.repo || 'nuxt/nuxt')
118
129
useSeoMeta({
1310
title: 'unsight.dev',

app/plugins/repos.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { isAllowedRepo } from '#shared/repos'
2+
3+
export default defineNuxtPlugin(() => {
4+
useRouter().beforeEach((to) => {
5+
if (to.query.repo && !isAllowedRepo(to.query.repo as string)) {
6+
return navigateTo('/')
7+
}
8+
})
9+
})

0 commit comments

Comments
 (0)