aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-11-08 16:13:48 +0900
committernsfisis <nsfisis@gmail.com>2025-11-08 16:13:48 +0900
commit4bd2fae1fe729d9cf82bd9e4b39d39f806ce5758 (patch)
tree684b9f49c6bcb8820d57318535badba66d3aeeb8 /frontend/src
parent2c81ffffaaee816f271b1bfe488e64d0288050fc (diff)
downloadfeedaka-4bd2fae1fe729d9cf82bd9e4b39d39f806ce5758.tar.gz
feedaka-4bd2fae1fe729d9cf82bd9e4b39d39f806ce5758.tar.zst
feedaka-4bd2fae1fe729d9cf82bd9e4b39d39f806ce5758.zip
refactor(frontend): Simplify AuthContextType
Diffstat (limited to 'frontend/src')
-rw-r--r--frontend/src/components/Navigation.tsx4
-rw-r--r--frontend/src/components/ProtectedRoute.tsx4
-rw-r--r--frontend/src/contexts/AuthContext.tsx17
3 files changed, 12 insertions, 13 deletions
diff --git a/frontend/src/components/Navigation.tsx b/frontend/src/components/Navigation.tsx
index 4d41d32..4be54a7 100644
--- a/frontend/src/components/Navigation.tsx
+++ b/frontend/src/components/Navigation.tsx
@@ -10,7 +10,7 @@ import { useAuth } from "../contexts/AuthContext";
import { MenuItem } from "./MenuItem";
export function Navigation() {
- const { logout, user } = useAuth();
+ const { logout, isLoggedIn } = useAuth();
const [, setLocation] = useLocation();
const handleLogout = async () => {
@@ -29,7 +29,7 @@ export function Navigation() {
<MenuItem path="/unread" label="Unread" icon={faBookOpen} />
<MenuItem path="/read" label="Read" icon={faCircleCheck} />
<MenuItem path="/settings" label="Settings" icon={faGear} />
- {user && (
+ {isLoggedIn && (
<button
type="button"
onClick={handleLogout}
diff --git a/frontend/src/components/ProtectedRoute.tsx b/frontend/src/components/ProtectedRoute.tsx
index 0cfef42..206e5c5 100644
--- a/frontend/src/components/ProtectedRoute.tsx
+++ b/frontend/src/components/ProtectedRoute.tsx
@@ -7,7 +7,7 @@ interface Props {
}
export function ProtectedRoute({ children }: Props) {
- const { user, isLoading } = useAuth();
+ const { isLoggedIn, isLoading } = useAuth();
if (isLoading) {
return (
@@ -24,7 +24,7 @@ export function ProtectedRoute({ children }: Props) {
);
}
- if (!user) {
+ if (!isLoggedIn) {
return <Redirect to="/login" />;
}
diff --git a/frontend/src/contexts/AuthContext.tsx b/frontend/src/contexts/AuthContext.tsx
index e43a1ec..4f374c7 100644
--- a/frontend/src/contexts/AuthContext.tsx
+++ b/frontend/src/contexts/AuthContext.tsx
@@ -8,17 +8,14 @@ import {
import { useMutation, useQuery } from "urql";
import {
GetCurrentUserDocument,
- type GetCurrentUserQuery,
LoginDocument,
LogoutDocument,
} from "../graphql/generated/graphql";
-type User = NonNullable<GetCurrentUserQuery["currentUser"]>;
-
type LoginResult = { success: true } | { success: false; error: string };
interface AuthContextType {
- user: User | null;
+ isLoggedIn: boolean;
isLoading: boolean;
error: string | null;
login: (username: string, password: string) => Promise<LoginResult>;
@@ -28,7 +25,7 @@ interface AuthContextType {
const AuthContext = createContext<AuthContextType | undefined>(undefined);
export function AuthProvider({ children }: { children: ReactNode }) {
- const [user, setUser] = useState<User | null>(null);
+ const [isLoggedIn, setIsLoggedIn] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
@@ -38,13 +35,13 @@ export function AuthProvider({ children }: { children: ReactNode }) {
query: GetCurrentUserDocument,
});
- // Update user from CurrentUser query
+ // Update isLoggedIn from CurrentUser query
useEffect(() => {
if (currentUserResult.data?.currentUser) {
- setUser(currentUserResult.data.currentUser);
+ setIsLoggedIn(true);
setError(null);
} else {
- setUser(null);
+ setIsLoggedIn(false);
}
if (currentUserResult.error) {
@@ -107,7 +104,9 @@ export function AuthProvider({ children }: { children: ReactNode }) {
};
return (
- <AuthContext.Provider value={{ user, isLoading, error, login, logout }}>
+ <AuthContext.Provider
+ value={{ isLoggedIn, isLoading, error, login, logout }}
+ >
{children}
</AuthContext.Provider>
);