Skip to content

Add frontend auth flow and session handling#90

Open
sudo-robi wants to merge 2 commits into
ericmt-98:mainfrom
sudo-robi:fix/frontend-auth-session
Open

Add frontend auth flow and session handling#90
sudo-robi wants to merge 2 commits into
ericmt-98:mainfrom
sudo-robi:fix/frontend-auth-session

Conversation

@sudo-robi
Copy link
Copy Markdown

closes #63

Copilot AI review requested due to automatic review settings May 26, 2026 15:56
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 26, 2026

@sudo-robi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Copy link
Copy Markdown

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds authentication flows to the frontend by introducing login/register pages, protecting existing routes, and improving auth/session handling.

Changes:

  • Added /login and /register routes plus a ProtectedRoute wrapper for authenticated-only pages.
  • Added an axios 401 response interceptor to clear stored users and redirect to login.
  • Updated TradeDetail tests to use new API functions and localStorage-based auth setup.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
micopay/frontend/tsconfig.json Adds trailing whitespace-only lines (formatting-only change).
micopay/frontend/src/services/api.ts Adds 401 interceptor to clear stored session and redirect to login.
micopay/frontend/src/pages/Register.tsx Introduces a new registration page UI and handler.
micopay/frontend/src/pages/Profile.tsx Adds a logout action in the profile screen.
micopay/frontend/src/pages/Login.tsx Introduces a new login page UI and login handler.
micopay/frontend/src/tests/TradeDetail.test.tsx Updates mocks and auth setup for TradeDetail tests.
micopay/frontend/src/App.tsx Adds auth routes, protected routing, demo-mode init changes, and login/logout wiring.
micopay/frontend/package.json Removes a platform-specific dependency entry.
Files not reviewed (1)
  • micopay/frontend/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1,5 +1,6 @@
import axios from 'axios';
import { extractApiErrorPayload } from '../utils/apiError';
import { removeKey } from './secureStorage';
Comment on lines +376 to +377
removeKey('micopay_users');
window.location.href = '/#/login';
Comment on lines +374 to +380
(error) => {
if (error.response?.status === 401) {
removeKey('micopay_users');
window.location.href = '/#/login';
}
return Promise.reject(error);
}
Comment on lines +7 to +23
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');

const handleRegister = async () => {
if (password !== confirmPassword) {
alert("Passwords don't match");
return;
}
try {
await registerUser(username);
navigate('/login');
} catch (error) {
console.error('Registration failed', error);
alert('Registration failed');
}
};
Comment on lines +14 to +24
const handleLogin = async () => {
// TODO: Implement actual login logic
console.log('Login button clicked');
const mockBuyer: UserData = {
id: 'mock-buyer-id',
username: username,
token: 'mock-buyer-token',
};
onLoginSuccess(mockBuyer, null);
navigate('/');
};
Comment on lines +332 to +341
function ProtectedRoute({ children }: { children: React.ReactElement }) {
const { buyerUser } = useAppCtx();
const location = useLocation();

if (!buyerUser) {
return <Navigate to="/login" state={{ from: location }} replace />;
}

return children;
}
const handleLoginSuccess = (buyer: UserData, seller: UserData | null) => {
setBuyerUser(buyer);
setSellerUser(seller);
writeJSON(USERS_STORAGE_KEY, { buyer, seller });
Comment on lines +34 to +45
const renderWithRouter = (route: string = '/trade/trade-123', isAuthenticated = true) => {
if (isAuthenticated) {
localStorage.setItem(
'micopay_users',
JSON.stringify({
buyer: { id: 'buyer-1', token: 'mock-token', username: 'test' },
seller: { id: 'seller-1', token: 'mock-token', username: 'test' },
}),
);
} else {
localStorage.removeItem('micopay_users');
}
Comment thread micopay/frontend/tsconfig.json Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Real login, register, logout and session recovery

2 participants