feat: switch to global auth and tenant route prefix
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
import { ref, onMounted, watch } from "vue";
|
||||
import { useRouter, useRoute } from "vue-router";
|
||||
import { ref, onMounted } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { tenantPath } from "../utils/tenant";
|
||||
|
||||
const isLoggedIn = ref(false);
|
||||
@@ -28,13 +28,6 @@ onMounted(() => {
|
||||
checkAuth();
|
||||
});
|
||||
|
||||
// Watch route changes to refresh auth state (e.g. after login redirect)
|
||||
watch(
|
||||
() => route.path,
|
||||
() => {
|
||||
checkAuth();
|
||||
},
|
||||
);
|
||||
|
||||
const logout = () => {
|
||||
localStorage.removeItem("token");
|
||||
@@ -102,10 +95,10 @@ const logout = () => {
|
||||
<div class="flex items-center gap-4">
|
||||
<template v-if="isLoggedIn">
|
||||
<!-- Notification -->
|
||||
<router-link
|
||||
:to="tenantRoute('/me/notifications')"
|
||||
class="relative w-10 h-10 flex items-center justify-center rounded-full hover:bg-slate-50 text-slate-600"
|
||||
>
|
||||
<router-link
|
||||
:to="tenantRoute('/me/notifications')"
|
||||
class="relative w-10 h-10 flex items-center justify-center rounded-full hover:bg-slate-50 text-slate-600"
|
||||
>
|
||||
<i class="pi pi-bell text-xl"></i>
|
||||
<span
|
||||
class="absolute top-2 right-2 w-2 h-2 bg-red-500 rounded-full border border-white"
|
||||
@@ -113,10 +106,10 @@ const logout = () => {
|
||||
</router-link>
|
||||
|
||||
<!-- Creator Entry -->
|
||||
<router-link
|
||||
:to="tenantRoute('/creator/apply')"
|
||||
class="hidden sm:flex items-center gap-1 px-3 py-1.5 text-sm font-medium text-slate-600 hover:bg-slate-50 rounded-lg border border-slate-200"
|
||||
>
|
||||
<router-link
|
||||
:to="tenantRoute('/creator/apply')"
|
||||
class="hidden sm:flex items-center gap-1 px-3 py-1.5 text-sm font-medium text-slate-600 hover:bg-slate-50 rounded-lg border border-slate-200"
|
||||
>
|
||||
<i class="pi pi-pencil"></i>
|
||||
<span>创作</span>
|
||||
</router-link>
|
||||
@@ -150,16 +143,16 @@ const logout = () => {
|
||||
{{ user.phone }}
|
||||
</p>
|
||||
</div>
|
||||
<router-link
|
||||
:to="tenantRoute('/me')"
|
||||
class="block px-4 py-2 text-sm text-slate-700 hover:bg-slate-50"
|
||||
>个人中心</router-link
|
||||
>
|
||||
<router-link
|
||||
:to="tenantRoute('/creator')"
|
||||
class="block px-4 py-2 text-sm text-slate-700 hover:bg-slate-50"
|
||||
>创作者中心</router-link
|
||||
>
|
||||
<router-link
|
||||
:to="tenantRoute('/me')"
|
||||
class="block px-4 py-2 text-sm text-slate-700 hover:bg-slate-50"
|
||||
>个人中心</router-link
|
||||
>
|
||||
<router-link
|
||||
:to="tenantRoute('/creator')"
|
||||
class="block px-4 py-2 text-sm text-slate-700 hover:bg-slate-50"
|
||||
>创作者中心</router-link
|
||||
>
|
||||
<div class="border-t border-slate-50 mt-1"></div>
|
||||
<button
|
||||
@click="logout"
|
||||
@@ -173,11 +166,11 @@ const logout = () => {
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<router-link
|
||||
:to="tenantRoute('/auth/login')"
|
||||
class="bg-primary-600 text-white px-6 py-2 rounded-full font-medium hover:bg-primary-700 transition-all shadow-sm shadow-primary-100 active:scale-95"
|
||||
>登录 / 注册</router-link
|
||||
>
|
||||
<router-link
|
||||
:to="'/auth/login'"
|
||||
class="bg-primary-600 text-white px-6 py-2 rounded-full font-medium hover:bg-primary-700 transition-all shadow-sm shadow-primary-100 active:scale-95"
|
||||
>登录 / 注册</router-link
|
||||
>
|
||||
</template>
|
||||
|
||||
<!-- Mobile Menu Button -->
|
||||
|
||||
Reference in New Issue
Block a user