direct login
This commit is contained in:
+23
@@ -139,7 +139,30 @@ const queryClient = new QueryClient({
|
||||
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 === Pages.auth.login) {
|
||||
window.location.href = Pages.dashboard
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const token = getToken()
|
||||
if (token) {
|
||||
setIsLogin('isLogin')
|
||||
|
||||
Reference in New Issue
Block a user