fix(auth): remove character context dependency
This commit is contained in:
@@ -5,12 +5,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { useEffect, useSyncExternalStore } from "react";
|
import { useEffect, useSyncExternalStore } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
import { MobileShell } from "@/app/_components/core";
|
import { MobileShell } from "@/app/_components/core";
|
||||||
import { useAuthState } from "@/stores/auth/auth-context";
|
import { useAuthState } from "@/stores/auth/auth-context";
|
||||||
import { isAuthenticatedUser } from "@/router/navigation-resolver";
|
import { isAuthenticatedUser } from "@/router/navigation-resolver";
|
||||||
import { ROUTES } from "@/router/routes";
|
import { ROUTES } from "@/router/routes";
|
||||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
|
||||||
|
|
||||||
import { AuthBackground, AuthPanel } from "./components";
|
import { AuthBackground, AuthPanel } from "./components";
|
||||||
import { Logger } from "@/utils/logger";
|
import { Logger } from "@/utils/logger";
|
||||||
@@ -19,7 +19,7 @@ const log = new Logger("AppAuthAuthScreen");
|
|||||||
|
|
||||||
export function AuthScreen() {
|
export function AuthScreen() {
|
||||||
const state = useAuthState();
|
const state = useAuthState();
|
||||||
const navigator = useAppNavigator();
|
const router = useRouter();
|
||||||
const redirectTo = useSyncExternalStore(
|
const redirectTo = useSyncExternalStore(
|
||||||
subscribeLocationSnapshot,
|
subscribeLocationSnapshot,
|
||||||
readRedirectFromLocation,
|
readRedirectFromLocation,
|
||||||
@@ -37,14 +37,14 @@ export function AuthScreen() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (shouldRedirect) {
|
if (shouldRedirect) {
|
||||||
log.debug("[auth-screen] useEffect → navigator.replace", {
|
log.debug("[auth-screen] useEffect → router.replace", {
|
||||||
redirectTo: safeRedirectTo,
|
redirectTo: safeRedirectTo,
|
||||||
});
|
});
|
||||||
navigator.replace(safeRedirectTo);
|
router.replace(safeRedirectTo);
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
state.loginStatus,
|
state.loginStatus,
|
||||||
navigator,
|
router,
|
||||||
safeRedirectTo,
|
safeRedirectTo,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { renderToStaticMarkup } from "react-dom/server";
|
import { renderToStaticMarkup } from "react-dom/server";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import { AuthScreen } from "../../auth-screen";
|
||||||
import { AuthBackground } from "../auth-background";
|
import { AuthBackground } from "../auth-background";
|
||||||
import { AuthEmailPanel } from "../auth-email-panel";
|
import { AuthEmailPanel } from "../auth-email-panel";
|
||||||
import { AuthErrorMessage } from "../auth-error-message";
|
import { AuthErrorMessage } from "../auth-error-message";
|
||||||
@@ -24,11 +25,15 @@ vi.mock("@/stores/auth/auth-context", () => ({
|
|||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@/router/use-app-navigator", () => ({
|
vi.mock("next/navigation", () => ({
|
||||||
useAppNavigator: () => ({ back: vi.fn() }),
|
useRouter: () => ({ back: vi.fn(), replace: vi.fn() }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("auth Tailwind components", () => {
|
describe("auth Tailwind components", () => {
|
||||||
|
it("renders outside CharacterProvider", () => {
|
||||||
|
expect(() => renderToStaticMarkup(<AuthScreen />)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
it("renders AuthErrorMessage only when a message is present", () => {
|
it("renders AuthErrorMessage only when a message is present", () => {
|
||||||
expect(renderToStaticMarkup(<AuthErrorMessage message={null} />)).toBe("");
|
expect(renderToStaticMarkup(<AuthErrorMessage message={null} />)).toBe("");
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
* 认证面板:顶层 switch(Facebook / Email)+ 悬浮返回按钮
|
* 认证面板:顶层 switch(Facebook / Email)+ 悬浮返回按钮
|
||||||
*/
|
*/
|
||||||
import { BackButton } from "@/app/_components";
|
import { BackButton } from "@/app/_components";
|
||||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
|
||||||
import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context";
|
import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
import { AuthEmailPanel } from "./auth-email-panel";
|
import { AuthEmailPanel } from "./auth-email-panel";
|
||||||
import { AuthFacebookPanel } from "./auth-facebook-panel";
|
import { AuthFacebookPanel } from "./auth-facebook-panel";
|
||||||
@@ -12,7 +12,7 @@ import { AuthFacebookPanel } from "./auth-facebook-panel";
|
|||||||
export function AuthPanel() {
|
export function AuthPanel() {
|
||||||
const state = useAuthState();
|
const state = useAuthState();
|
||||||
const dispatch = useAuthDispatch();
|
const dispatch = useAuthDispatch();
|
||||||
const navigator = useAppNavigator();
|
const router = useRouter();
|
||||||
|
|
||||||
const switchToFacebook = () =>
|
const switchToFacebook = () =>
|
||||||
dispatch({ type: "AuthPanelModeChanged", mode: "facebook" });
|
dispatch({ type: "AuthPanelModeChanged", mode: "facebook" });
|
||||||
@@ -23,7 +23,7 @@ export function AuthPanel() {
|
|||||||
if (state.authPanelMode === "email") {
|
if (state.authPanelMode === "email") {
|
||||||
switchToFacebook();
|
switchToFacebook();
|
||||||
} else {
|
} else {
|
||||||
navigator.back();
|
router.back();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user