feat: add customer login page in SPA

- Created Login/index.tsx with styled form
- Added /auth/customer-login API endpoint (no admin perms required)
- Registered route in Routes.php
- Added /login route in customer-spa App.tsx
- Account page now redirects to SPA login instead of wp-login.php
- Login supports redirect param for post-login navigation
This commit is contained in:
Dwindi Ramadhana
2025-12-31 22:43:13 +07:00
parent 3d7eb5bf48
commit 56042d4b8e
5 changed files with 242 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
import Container from '@/components/Layout/Container';
import { AccountLayout } from './components/AccountLayout';
import Dashboard from './Dashboard';
@@ -12,11 +12,12 @@ import AccountDetails from './AccountDetails';
export default function Account() {
const user = (window as any).woonoowCustomer?.user;
const location = useLocation();
// Redirect to login if not authenticated
if (!user?.isLoggedIn) {
window.location.href = '/wp-login.php?redirect_to=' + encodeURIComponent(window.location.href);
return null;
const currentPath = location.pathname;
return <Navigate to={`/login?redirect=${encodeURIComponent(currentPath)}`} replace />;
}
return (