Commit 4acd889b authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

RequireAuth 추가에 따른 from 경로 추가

parent 9388110e
import React, { ChangeEvent, FormEvent, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";
import { catchErrors } from "../helpers";
import { SpinnerIcon } from "../icons";
import { useAuth } from "./auth.context";
interface LocationState {
state: { from: string };
}
export const Login = () => {
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [loginData, setLoginData] = useState({ email: "", password: "" });
const navigate = useNavigate();
const location = useLocation() as LocationState;
const { login } = useAuth();
const from = location.state.from || "/";
function handleChange(e: ChangeEvent<HTMLInputElement>) {
const { name, value } = e.currentTarget;
setLoginData({ ...loginData, [name]: value });
......@@ -18,11 +25,10 @@ export const Login = () => {
async function handleSubmit(e: FormEvent) {
e.preventDefault();
console.log(loginData);
const { email, password } = loginData;
try {
setLoading(true);
await login(email, password, () => navigate("/", { replace: true }));
await login(email, password, () => navigate(from, { replace: true }));
} catch (error) {
setLoading(false);
catchErrors(error, setError);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment