feat(partner): require WeChat OAuth before store photo upload
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { Routes, Route, Navigate, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { useEffect } from 'react';
|
||||
import TabLayout from './layouts/TabLayout';
|
||||
import LoginPage from './pages/LoginPage';
|
||||
import HomePage from './pages/HomePage';
|
||||
@@ -12,10 +13,37 @@ import BillsPage from './pages/BillsPage';
|
||||
import ReshipPage from './pages/ReshipPage';
|
||||
import WeeklyReportPage from './pages/WeeklyReportPage';
|
||||
import LeaderboardPage from './pages/LeaderboardPage';
|
||||
import { handlePartnerWechatCallback, savePartnerWechatAuth } from './lib/wechat-auth';
|
||||
import { isWechatEnv } from './lib/weixin';
|
||||
|
||||
function WechatOAuthHandler() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isWechatEnv() || !location.search.includes('code=')) return;
|
||||
void handlePartnerWechatCallback()
|
||||
.then((result) => {
|
||||
if (!result || !savePartnerWechatAuth(result)) return;
|
||||
const params = new URLSearchParams(location.search);
|
||||
params.delete('code');
|
||||
params.delete('state');
|
||||
const qs = params.toString();
|
||||
navigate(`${location.pathname}${qs ? `?${qs}` : ''}`, { replace: true });
|
||||
})
|
||||
.catch(() => {
|
||||
/* 页面内组件会提示 */
|
||||
});
|
||||
}, [location.pathname, location.search, navigate]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<>
|
||||
<WechatOAuthHandler />
|
||||
<Routes>
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route element={<TabLayout />}>
|
||||
<Route path="/" element={<HomePage />} />
|
||||
@@ -32,5 +60,6 @@ export default function App() {
|
||||
<Route path="/orders/:id" element={<OrderDetailPage />} />
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user