diff --git a/app/components/TopNav.vue b/app/components/TopNav.vue
index 0fb8c28..3cd6e29 100644
--- a/app/components/TopNav.vue
+++ b/app/components/TopNav.vue
@@ -6,6 +6,7 @@ const navHidden = ref(false)
const route = useRoute()
const { loggedIn, user, clear, initialized } = useAuthSession()
+const { config: globalConfig } = useGlobalConfig()
const links: any = [
{ to: "/", label: "首页" },
@@ -66,7 +67,7 @@ watch(() => route.path, () => {
登录
- 注册
+ 注册
{{ user?.username }}
@@ -75,7 +76,7 @@ watch(() => route.path, () => {
登录
- 注册
+ 注册
管理
diff --git a/app/middleware/auth.global.ts b/app/middleware/auth.global.ts
index 99d4032..9e943a8 100644
--- a/app/middleware/auth.global.ts
+++ b/app/middleware/auth.global.ts
@@ -5,7 +5,7 @@ import {
normalizeSafeRedirect,
} from "@/utils/auth-routes";
import { useAuthSession } from "../composables/useAuthSession";
-import { FRONTEND_LOGIN_PATH } from "common/config"
+import { FRONTEND_LOGIN_PATH, FRONTEND_REGISTER_PATH } from "common/config"
export default defineNuxtRouteMiddleware(async (to) => {
if(to.path.startsWith("/__nuxt_error")) {
@@ -45,6 +45,15 @@ export default defineNuxtRouteMiddleware(async (to) => {
});
}
+ if (!isLoggedIn && currentPath === FRONTEND_REGISTER_PATH) {
+ const { config: globalConfig } = useGlobalConfig();
+ if (globalConfig.value.allowRegister === false) {
+ const { $toast } = useNuxtApp();
+ $toast?.warning("当前已关闭注册");
+ return navigateTo(FRONTEND_LOGIN_PATH);
+ }
+ }
+
if (isLoggedIn && isGuestOnlyRoute(currentPath)) {
const redirectCandidate = Array.isArray(to.query.redirect)
? to.query.redirect[0]
diff --git a/app/pages/auth/login.vue b/app/pages/auth/login.vue
index bd94093..6234433 100644
--- a/app/pages/auth/login.vue
+++ b/app/pages/auth/login.vue
@@ -5,6 +5,7 @@ definePageMeta({
const route = useRoute()
const { $toast } = useNuxtApp()
+const { config: globalConfig } = useGlobalConfig()
const redirect = computed(() => route.query.redirect as string || '/')
const loginForm = reactive({
@@ -172,7 +173,7 @@ onMounted(() => {
-->
-
diff --git a/app/pages/auth/register.vue b/app/pages/auth/register.vue
index a3758f5..97ac6b6 100644
--- a/app/pages/auth/register.vue
+++ b/app/pages/auth/register.vue
@@ -4,6 +4,14 @@ definePageMeta({
})
const { $toast } = useNuxtApp()
+const { config: globalConfig } = useGlobalConfig()
+
+watch(() => globalConfig.allowRegister, (val) => {
+ if (val === false) {
+ $toast.error('当前已关闭注册')
+ navigateTo('/auth/login')
+ }
+}, { immediate: true })
const registerForm = reactive({
username: '',
diff --git a/packages/drizzle-pkg/db.sqlite b/packages/drizzle-pkg/db.sqlite
index 2ee02d5..d7a1223 100644
Binary files a/packages/drizzle-pkg/db.sqlite and b/packages/drizzle-pkg/db.sqlite differ