added refresh token
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user