Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
survey
Commits
4acd889b
Commit
4acd889b
authored
Jul 07, 2022
by
Yoon, Daeki
😅
Browse files
RequireAuth 추가에 따른 from 경로 추가
parent
9388110e
Changes
1
Hide whitespace changes
Inline
Side-by-side
frontend/src/auth/Login.tsx
View file @
4acd889b
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment