From 341e2331a049bedd17d8256ccccd1d15173615d9 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Wed, 25 Feb 2026 00:41:01 +0800 Subject: [PATCH] feat(auth): enhance authentication flow with dynamic login page configuration and navigation updates --- src/pages/auth/index.tsx | 15 +++++----- src/pages/auth/modules/BaseHeader.tsx | 31 +++++++++++--------- src/pages/auth/page.tsx | 42 +++++++++++++++++++++++---- src/pages/auth/store.ts | 35 ++++++++++++++++++++-- 4 files changed, 94 insertions(+), 29 deletions(-) diff --git a/src/pages/auth/index.tsx b/src/pages/auth/index.tsx index e02d241..ac827c7 100644 --- a/src/pages/auth/index.tsx +++ b/src/pages/auth/index.tsx @@ -4,10 +4,8 @@ import { useShallow } from "zustand/shallow" import { LogIn, LockKeyhole } from "lucide-react" export { BaseHeader } from './modules/BaseHeader' import { useMemo } from 'react'; -import { useLocation } from '@tanstack/react-router'; -const openLinkList = [ - '/login' -] +import { useLocation, useNavigate } from '@tanstack/react-router'; + type Props = { children?: React.ReactNode, @@ -17,16 +15,16 @@ export const AuthProvider = ({ children, mustLogin }: Props) => { const store = useLayoutStore(useShallow(state => ({ init: state.init, me: state.me, + openLinkList: state.openLinkList, }))); useEffect(() => { store.init() }, []) const location = useLocation() + const navigate = useNavigate(); const isOpen = useMemo(() => { - console.log('location.pathname', location.pathname, openLinkList) - return openLinkList.some(item => location.pathname.startsWith(item)) + return store.openLinkList.some(item => location.pathname.startsWith(item)) }, [location.pathname]) - console.log('AuthProvider', { location, isOpen, me: store.me }) const loginUrl = '/root/login/?redirect=' + encodeURIComponent(window.location.href); if (mustLogin && !store.me && !isOpen) { return ( @@ -42,7 +40,8 @@ export const AuthProvider = ({ children, mustLogin }: Props) => {
{ - window.open(loginUrl, '_self') + // window.open(loginUrl, '_blank'); + navigate({ to: '/login' }); }} > diff --git a/src/pages/auth/modules/BaseHeader.tsx b/src/pages/auth/modules/BaseHeader.tsx index be65de6..d93cee2 100644 --- a/src/pages/auth/modules/BaseHeader.tsx +++ b/src/pages/auth/modules/BaseHeader.tsx @@ -1,5 +1,5 @@ import { Home, User, LogIn, LogOut } from 'lucide-react'; -import { Link } from '@tanstack/react-router' +import { Link, useNavigate } from '@tanstack/react-router' import { useLayoutStore } from '../store'; import { useShallow } from 'zustand/shallow'; import { useMemo } from 'react'; @@ -8,13 +8,14 @@ export const BaseHeader = (props: { main?: React.ComponentType | null }) => { const store = useLayoutStore(useShallow(state => ({ me: state.me, clearMe: state.clearMe, + links: state.links, }))); - + const navigate = useNavigate(); const meInfo = useMemo(() => { if (!store.me) { return (