added refresh token

This commit is contained in:
SlimusMinus
2026-08-03 02:44:57 +03:00
parent b6c61c72d9
commit abbcc330e7
16 changed files with 210 additions and 135 deletions

View File

@@ -1,6 +1,7 @@
import { useState, useEffect } from "react";
import {API_URL} from "../config/authConstants";
import { useNavigate } from "react-router-dom";
import { API_URL } from "../config/authConstants";
import { saveTokens } from "../api/apiClient";
export function useCheckLogin(login) {
const [checking, setChecking] = useState(false);
@@ -15,7 +16,7 @@ export function useCheckLogin(login) {
const timer = setTimeout(async () => {
try {
setChecking(true);
const res = await fetch(`${API_URL}/api/v1/auth/check-login?login=${login}`);
const res = await fetch(`${API_URL}/api/v1/auth/check-login?login=${encodeURIComponent(login)}`);
const json = await res.json();
setExists(json.exists);
} catch (e) {
@@ -31,8 +32,8 @@ export function useCheckLogin(login) {
return { checking, exists };
}
export function useRegister() {
const navigate = useNavigate();
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const [success, setSuccess] = useState(false);
@@ -54,10 +55,9 @@ export function useRegister() {
throw new Error(data.message || "Ошибка регистрации");
}
saveTokens(data.token, data.refreshToken);
setSuccess(true);
setTimeout(() => {
window.location.href = "/register";
}, 2500);
setTimeout(() => navigate("/feed"), 1500);
} catch (e) {
setError(e.message);
} finally {