우주먼지 개발 log
[세션] 중복코드를 관리하는 법 feat. 소셜로그인 본문
반응형
이런 코드를 줄여보자.
const signInWithGoogle = () => {
const googleProvider = new GoogleAuthProvider();
return signInWithPopup(authService, googleProvider);
};
const signInWithGithub = () => {
const githubProvider = new GithubAuthProvider();
return signInWithPopup(authService, githubProvider);
};
const socialGoogleLoginhandler = async (event) => {
event.preventDefault();
await signInWithGoogle()
.then((res) => {
const credential = GoogleAuthProvider.credentialFromResult(res);
const token = credential.accessToken;
const userName = res.user.displayName;
// local storage에 token, username 저장해주기
console.log(token);
console.log(userName);
navigate("/");
})
.catch((error) => {
console.error(error);
});
};
const socialGithubLoginhandler = async (event) => {
event.preventDefault();
await signInWithGithub()
.then((res) => {
const credential = GithubAuthProvider.credentialFromResult(res);
const token = credential.accessToken; // 로그인된 값
const userName = res.user.displayName; // 유저이름
// local storage에 token, username 저장해주기
console.log(token);
console.log(userName);
navigate("/");
})
.catch((error) => {
console.error(error);
});
};
- TOBE 코드 참고
https://github.com/JaeSang1998/sparta-lecture
GitHub - JaeSang1998/sparta-lecture
Contribute to JaeSang1998/sparta-lecture development by creating an account on GitHub.
github.com
내배캠 과정 추가 세션 중 가장유용했던
재상튜터님의
쟝님 코드 줄이기 ^.^
빠른시일내에 복습할 것 !!
반응형
'TIL(Today I Learned) > 스파르타 내배캠' 카테고리의 다른 글
[세션] 리덕스 특강 (0) | 2024.02.22 |
---|---|
[세션] Authentication 인증 (0) | 2024.02.20 |
[스파르타 내일배움캠프][후기] React_3기 찐 프론트엔드 개발자가 되는 과정 >.< (2) | 2024.02.16 |
[취업준비] 이력서 완성 주차, 2일차 (1) | 2024.02.15 |
[취업준비] 이력서 완성주차, 타임테이블 ^.^ (0) | 2024.02.12 |