direct login

This commit is contained in:
hamid zarghami
2026-03-12 12:57:01 +03:30
parent 36a1caba0f
commit 07a05e770b
3 changed files with 51 additions and 6 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
VITE_API_URL = 'http://10.109.87.88:4000' VITE_API_URL = 'http://10.165.85.88:4000'
VITE_TOKEN_NAME = 'dpage-editor-t' VITE_TOKEN_NAME = 'dpage-editor-t'
VITE_REFRESH_TOKEN_NAME = 'dpage-editor-t' VITE_REFRESH_TOKEN_NAME = 'dpage-editor-t'
+44 -1
View File
@@ -1,4 +1,4 @@
import { type FC } from 'react' import { useEffect, useState, type FC } from 'react'
import './assets/fonts/irancell/style.css' import './assets/fonts/irancell/style.css'
import { BrowserRouter } from 'react-router-dom' import { BrowserRouter } from 'react-router-dom'
import MainRouter from './router/MainRouter' import MainRouter from './router/MainRouter'
@@ -7,6 +7,7 @@ import FaJson from '@/langs/fa.json'
import { I18nextProvider } from 'react-i18next' import { I18nextProvider } from 'react-i18next'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import ToastContainer from './components/Toast' import ToastContainer from './components/Toast'
import { getToken, setRefreshToken, setToken } from './config/func'
i18next.init({ i18next.init({
interpolation: { escapeValue: false }, interpolation: { escapeValue: false },
@@ -21,6 +22,48 @@ i18next.init({
const queryClient = new QueryClient() const queryClient = new QueryClient()
const App: FC = () => { const App: FC = () => {
const [isLogin, setIsLogin] = useState<'checking' | 'isLogin' | 'isNotLogin'>('checking')
useEffect(() => {
// استخراج توکن‌ها از URL در صورت وجود
const urlParams = new URLSearchParams(window.location.search)
const tokenFromUrl = urlParams.get('token')
const refreshTokenFromUrl = urlParams.get('refreshToken')
if (tokenFromUrl && refreshTokenFromUrl) {
// ذخیره توکن‌ها (جایگزین کردن توکن‌های قبلی اگر وجود داشته باشند)
setToken(tokenFromUrl)
setRefreshToken(refreshTokenFromUrl)
// حذف پارامترها از URL
const newUrl = window.location.pathname
window.history.replaceState({}, '', newUrl)
// تنظیم وضعیت لاگین و هدایت به صفحه اصلی
setIsLogin('isLogin')
// if (window.location.pathname === Paths.auth.login) {
// window.location.href = Paths.home
// }
return
}
const token = getToken()
if (token) {
setIsLogin('isLogin')
} else {
setIsLogin('isNotLogin')
if (window.location.href.split('auth').length === 1) {
// window.location.href = Paths.auth.login
}
}
}, [])
console.log('isLogin', isLogin);
return ( return (
<BrowserRouter> <BrowserRouter>
<I18nextProvider i18n={i18next}> <I18nextProvider i18n={i18next}>
+6 -4
View File
@@ -9,22 +9,24 @@ import type {
} from "@/pages/catalogue/types/Types"; } from "@/pages/catalogue/types/Types";
export const createCatalog = async (params: CreateCatalogParamsType) => { export const createCatalog = async (params: CreateCatalogParamsType) => {
const { data } = await axios.post("/catalogue", params); const { data } = await axios.post("/admin/catalogue", params);
return data; return data;
}; };
export const getCatalogs = async () => { export const getCatalogs = async () => {
const { data } = await axios.get<CatalogResponseType>("/catalogue"); const { data } = await axios.get<CatalogResponseType>("/admin/catalogue");
return data; return data;
}; };
export const getCatalogById = async (id: string) => { export const getCatalogById = async (id: string) => {
const { data } = await axios.get<CatalogByIdResponseType>(`/catalogue/${id}`); const { data } = await axios.get<CatalogByIdResponseType>(
`/admin/catalogue/${id}`,
);
return data; return data;
}; };
export const updateCatalog = async (params: UpdateCatalogParamsType) => { export const updateCatalog = async (params: UpdateCatalogParamsType) => {
const { data } = await axios.patch(`/catalogue/${params.id}`, { const { data } = await axios.patch(`/admin/catalogue/${params.id}`, {
content: params.content, content: params.content,
}); });
return data; return data;