Add frontend auth flow and session handling#90
Open
sudo-robi wants to merge 2 commits into
Open
Conversation
|
@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! 🚀 |
There was a problem hiding this comment.
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
/loginand/registerroutes plus aProtectedRoutewrapper 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'); | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #63