Skip to content

Conversation

zigzagdev
Copy link
Owner

Description

  • Implemented actual API call to check login status.
  • Removed all mock logic related to login state.
  • Updated context/provider to handle real responses.
  • Ensured fallback behaviour on invalid/expired tokens.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces mock authentication logic with real API integration for user login status verification. The changes implement proper token-based authentication using localStorage and centralize API endpoint configuration.

  • Removed hardcoded mock user data and replaced it with actual API calls to fetch user profiles
  • Added centralized API endpoint configuration with environment variable support
  • Enhanced error handling and token cleanup for authentication failures

Reviewed Changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/context/AuthContext.tsx Replaced mock authentication logic with real API calls using token validation
src/constants/env.ts Added centralized API endpoint configuration with environment variable support

const logout = async () => {
try {
await logoutUser();
await logoutUser(); // 通常のAPI logout
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment contains Japanese text ('通常のAPI logout'). Consider using English for consistency with the rest of the codebase, such as '// Standard API logout'.

Suggested change
await logoutUser(); // 通常のAPI logout
await logoutUser(); // Standard API logout

Copilot uses AI. Check for mistakes.

},
posts: {
create: `${API_BASE_URL}/posts`,
list:(id: string) => `${API_BASE_URL}/users/${id}/posts`,
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing space after colon in the object property. Should be 'list: (id: string) =>' for consistent formatting.

Suggested change
list:(id: string) => `${API_BASE_URL}/users/${id}/posts`,
list: (id: string) => `${API_BASE_URL}/users/${id}/posts`,

Copilot uses AI. Check for mistakes.

const userProfile = await fetchUserProfile(userId, token);
setUser(userProfile);
} catch (error) {
console.error('Failed to fetch user profile:', error);
Copy link

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the full error object may expose sensitive information in production. Consider logging only the error message or a sanitized version of the error.

Suggested change
console.error('Failed to fetch user profile:', error);
console.error('Failed to fetch user profile:', error instanceof Error ? error.message : String(error));

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant