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
b81df368
Commit
b81df368
authored
Dec 25, 2022
by
Jiwon Yoon
Browse files
kakaologin
parent
90b3d3d6
Changes
1
Show whitespace changes
Inline
Side-by-side
frontend/src/auth/OAuthRedirectHandler.tsx
View file @
b81df368
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
{
authApi
}
from
"
../apis
"
;
import
{
catchErrors
}
from
"
../helpers
"
;
const
LOCAL_USER_INFO
=
"
survey-user-info
"
;
export
const
OAuthRedirectHandler
=
()
=>
{
const
[
error
,
setError
]
=
useState
(
""
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
message
,
setMessage
]
=
useState
(
"
잠시만 기다려 주세요! 로그인 중입니다.
"
);
...
...
@@ -12,13 +17,26 @@ export const OAuthRedirectHandler = () => {
},
[]);
useEffect
(()
=>
{
const
getKakaoUserData
=
async
(
code
:
string
)
=>
{
const
userData
=
await
authApi
.
getKakaoUserData
(
code
);
console
.
log
(
userData
);
const
kakaoLogin
=
async
(
code
:
string
)
=>
{
try
{
const
user
=
await
authApi
.
getKakaoUserData
(
code
);
console
.
log
(
user
);
if
(
user
)
{
localStorage
.
setItem
(
LOCAL_USER_INFO
,
JSON
.
stringify
({
isLoggedIn
:
user
.
isLoggedIn
,
})
);
}
}
catch
(
error
)
{
setLoading
(
false
);
catchErrors
(
error
,
setError
);
}
};
if
(
code
)
{
console
.
log
(
"
code=
"
,
code
);
getKakaoUserData
(
code
);
kakaoLogin
(
code
);
}
},
[
code
]);
...
...
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