修复TV端登录失效误跳/login:按路径跳转到/tv/login
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
import { getAuthInfoFromBrowserCookie, clearAuthCookie } from './auth';
|
||||
import { normalizeEpisodeFilterConfig } from './episode-filter';
|
||||
import { MangaReadRecord, MangaShelfItem } from './manga.types';
|
||||
import { isLoginPathname, resolveLoginPath } from './tv-mode';
|
||||
import { DanmakuFilterConfig, EpisodeFilterConfig, SkipConfig } from './types';
|
||||
|
||||
// 全局错误触发函数
|
||||
@@ -661,7 +662,7 @@ export async function fetchWithAuth(
|
||||
// 如果在登录页面,跳过刷新逻辑
|
||||
if (
|
||||
typeof window !== 'undefined' &&
|
||||
window.location.pathname === '/login'
|
||||
isLoginPathname(window.location.pathname)
|
||||
) {
|
||||
console.log('[fetchWithAuth] On login page, skipping refresh logic');
|
||||
return res;
|
||||
@@ -707,7 +708,7 @@ export async function fetchWithAuth(
|
||||
// 检查当前页面是否已经是登录页,避免重复跳转
|
||||
if (
|
||||
typeof window !== 'undefined' &&
|
||||
!window.location.pathname.startsWith('/login')
|
||||
!isLoginPathname(window.location.pathname)
|
||||
) {
|
||||
// 调用 logout 接口
|
||||
try {
|
||||
@@ -721,7 +722,10 @@ export async function fetchWithAuth(
|
||||
clearAuthCookie();
|
||||
}
|
||||
const currentUrl = window.location.pathname + window.location.search;
|
||||
const loginUrl = new URL('/login', window.location.origin);
|
||||
const loginUrl = new URL(
|
||||
resolveLoginPath(window.location.pathname),
|
||||
window.location.origin
|
||||
);
|
||||
loginUrl.searchParams.set('redirect', currentUrl);
|
||||
window.location.href = loginUrl.toString();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
export function isTVModeEnabled() {
|
||||
return process.env.ENABLE_TV_MODE !== 'false';
|
||||
}
|
||||
|
||||
export function isTVPathname(pathname: string): boolean {
|
||||
return pathname === '/tv' || pathname.startsWith('/tv/');
|
||||
}
|
||||
|
||||
/** 按当前路径选择登录页:TV 端走 /tv/login,其余走 /login */
|
||||
export function resolveLoginPath(pathname: string): string {
|
||||
return isTVPathname(pathname) ? '/tv/login' : '/login';
|
||||
}
|
||||
|
||||
export function isLoginPathname(pathname: string): boolean {
|
||||
return pathname === '/login' || pathname === '/tv/login';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user