Merge pull request #3 from SlimusMinus/auth_on_back
deleted another authentication
This commit is contained in:
@@ -7,20 +7,20 @@ export function useAuth() {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
const login = async (email, password) => {
|
const login = async (login, password) => {
|
||||||
if (!email || !password) { setError("Введи email и пароль"); return; }
|
if (!login || !password) { setError("Введи login и пароль"); return; }
|
||||||
setLoading(true); setError("");
|
setLoading(true); setError("");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/api/auth/login`, {
|
const res = await fetch(`${API_URL}/api/v1/auth`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ email, password }),
|
body: JSON.stringify({ login, password }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const data = await res.json().catch(() => ({}));
|
const data = await res.json().catch(() => ({}));
|
||||||
throw new Error(data.message || "Неверный email или пароль");
|
throw new Error(data.message || "Неверный login или пароль");
|
||||||
}
|
}
|
||||||
|
|
||||||
const { token, user } = await res.json();
|
const { token, user } = await res.json();
|
||||||
@@ -34,21 +34,6 @@ export function useAuth() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loginGoogle = () => { /* TODO: @react-oauth/google */ };
|
|
||||||
|
|
||||||
const loginYandex = () => {
|
return { login, loading, error };
|
||||||
const clientId = process.env.REACT_APP_YANDEX_CLIENT_ID;
|
|
||||||
const redirect = encodeURIComponent(`${window.location.origin}/auth/yandex`);
|
|
||||||
window.location.href =
|
|
||||||
`https://oauth.yandex.ru/authorize?response_type=code&client_id=${clientId}&redirect_uri=${redirect}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const loginVK = () => {
|
|
||||||
const appId = process.env.REACT_APP_VK_APP_ID;
|
|
||||||
const redirect = encodeURIComponent(`${window.location.origin}/auth/vk`);
|
|
||||||
window.location.href =
|
|
||||||
`https://oauth.vk.com/authorize?client_id=${appId}&redirect_uri=${redirect}&response_type=code&scope=email`;
|
|
||||||
};
|
|
||||||
|
|
||||||
return { login, loginGoogle, loginYandex, loginVK, loading, error };
|
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ import { s } from "../styles/loginStyles";
|
|||||||
import "../styles/global.css";
|
import "../styles/global.css";
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const [email, setEmail] = useState("");
|
const [loginValue, setEmail] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
const [showPass, setShowPass] = useState(false);
|
const [showPass, setShowPass] = useState(false);
|
||||||
|
|
||||||
@@ -30,11 +30,11 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
<h1 style={s.title}>Находка</h1>
|
<h1 style={s.title}>Находка</h1>
|
||||||
|
|
||||||
<form onSubmit={(e) => { e.preventDefault(); login(email, password); }} noValidate>
|
<form onSubmit={(e) => { e.preventDefault(); login(loginValue, password); }} noValidate>
|
||||||
<div style={s.inputWrap}>
|
<div style={s.inputWrap}>
|
||||||
<input
|
<input
|
||||||
type="email" placeholder="Введите email"
|
type="email" placeholder="Введите email"
|
||||||
value={email} onChange={(e) => setEmail(e.target.value)}
|
value={loginValue} onChange={(e) => setEmail(e.target.value)}
|
||||||
style={s.input} className="li"
|
style={s.input} className="li"
|
||||||
autoComplete="off" name="naidishchey-email-x7k"
|
autoComplete="off" name="naidishchey-email-x7k"
|
||||||
readOnly onFocus={(e) => e.target.removeAttribute("readOnly")}
|
readOnly onFocus={(e) => e.target.removeAttribute("readOnly")}
|
||||||
@@ -67,15 +67,6 @@ export default function LoginPage() {
|
|||||||
Нет аккаунта? <a href="/register" style={s.link}>Зарегистрироваться</a>
|
Нет аккаунта? <a href="/register" style={s.link}>Зарегистрироваться</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div style={s.divider} className="div-line">
|
|
||||||
<span style={s.divText}>или</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={s.socials}>
|
|
||||||
<button onClick={loginGoogle} style={s.socBtn} className="soc">Google</button>
|
|
||||||
<button onClick={loginYandex} style={{ ...s.socBtn, color: "#ffcc00" }} className="soc">Яндекс</button>
|
|
||||||
<button onClick={loginVK} style={{ ...s.socBtn, color: "#5b9bd5" }} className="soc">ВК</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user