-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] 로그인 페이지 구현 #286
[Feat] 로그인 페이지 구현 #286
Changes from all commits
cc2dd09
cb66913
f1e77cb
5f77458
7954c1b
bb847cf
48de519
966b9ae
4dcbe1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,16 @@ export class AuthService { | |
|
||
async createGuestUser() { | ||
const randomNum = Math.floor(Math.random() * 10000); | ||
const response = await fetch('https://api.thecatapi.com/v1/images/search'); | ||
const catImageUrl = (await response.json())[0].url; | ||
|
||
const guestUser = { | ||
username: `guest_${randomNum}`, | ||
password: `guest_password_${randomNum}`, | ||
email: `[email protected]`, | ||
nickname: `guest_${randomNum}`, | ||
introduce: `게스트 사용자입니다. `, | ||
profileImageUrl: `https://cataas.com/cat?${Date.now()}`, | ||
profileImageUrl: catImageUrl, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p2: 이미지를 가져오기 위해 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 이건 여러 게스트 유저를 만들어서 더미를 쌓아놓을 때 기본 이미지보다는 랜덤한 고양이 이미지 들어오는게 단순히 귀엽고 보기 좋을거같아서 넣기는 했습니다 😅 혹시 우려되는 문제가 있을까요? 🥲 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. http 요청으로 인해 성능상 좋지 않을 것으로 생성되지만... 고양이 귀엽죠... 우선 두고 테스트 진행하며 문제 발생시 변경해도 좋을 것 같습니다!!! 고양이 지켜!! |
||
}; | ||
const user = await this.userService.findUserByUsername(guestUser.username); | ||
if (!user) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import axiosInstance from '@/api/axios'; | ||
import { ENV } from '@/constants/env'; | ||
|
||
type SignUpDto = { | ||
username: string; | ||
|
@@ -23,8 +24,12 @@ const signOut = async () => { | |
await axiosInstance.post('/auth/logout'); | ||
}; | ||
|
||
const oauthLogin = async (provider: 'google' | 'github') => { | ||
await axiosInstance.get(`/auth/${provider}/login`); | ||
const guestLogin = () => { | ||
window.location.href = `${ENV.API_URL}/auth/guest/login`; | ||
}; | ||
|
||
export { logIn, signUp, oauthLogin, signOut }; | ||
const oauthLogin = (provider: 'google' | 'github') => { | ||
window.location.href = `${ENV.API_URL}/auth/${provider}/login`; | ||
}; | ||
Comment on lines
-26
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p1: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로그인 버튼을 눌렀을 때 해당 주소에서 GET을 해야하기 때문에 axios GET 요청이 아닌 링크 이동으로 구현하게 되었습니다! |
||
|
||
export { logIn, signUp, oauthLogin, guestLogin, signOut }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { guestLogin } from '@/api/auth'; | ||
import ChevronRight from '@/assets/icons/chevron-right.svg?react'; | ||
|
||
function GuestLogin() { | ||
const handleGuestLogin = () => { | ||
guestLogin(); | ||
}; | ||
|
||
return ( | ||
<span | ||
className="mt-3 flex items-center gap-1.5 text-title2 text-main" | ||
onClick={handleGuestLogin} | ||
> | ||
게스트 로그인 | ||
<ChevronRight className="w-2 fill-black" /> | ||
</span> | ||
); | ||
} | ||
|
||
export default GuestLogin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { cva } from 'class-variance-authority'; | ||
|
||
import { oauthLogin } from '@/api/auth'; | ||
import GithubIc from '@/assets/icons/github.svg?react'; | ||
import GoogleIc from '@/assets/icons/google.svg?react'; | ||
|
||
const oauthButton = cva('flex w-96 justify-center gap-3 rounded-lg py-4 shadow-normal', { | ||
variants: { | ||
type: { | ||
github: 'bg-black text-white', | ||
google: 'border border-main bg-white text-alt', | ||
}, | ||
}, | ||
defaultVariants: { | ||
type: 'github', | ||
}, | ||
}); | ||
|
||
const OAUTH_LABEL = { | ||
github: 'Github', | ||
google: 'Google', | ||
} as const; | ||
|
||
type OAuthType = keyof typeof OAUTH_LABEL; | ||
|
||
interface OAuthLoginProps { | ||
type: OAuthType; | ||
} | ||
|
||
function OAuthLogin({ type }: OAuthLoginProps) { | ||
const onLoginBtnClick = (type: OAuthType) => { | ||
oauthLogin(type); | ||
}; | ||
|
||
return ( | ||
<button type="button" className={oauthButton({ type })} onClick={() => onLoginBtnClick(type)}> | ||
{type === 'github' ? <GithubIc /> : <GoogleIc />} | ||
<span className="text-head3">{OAUTH_LABEL[type]} 계정으로 로그인</span> | ||
</button> | ||
); | ||
} | ||
|
||
export default OAuthLogin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import TicleCharacterBadge from '@/assets/images/ticle-character-badge.png'; | ||
import TicleLogo from '@/assets/ticle.svg?react'; | ||
|
||
import GuestLogin from './GuestLogin'; | ||
import OAuthLogin from './OAuthLogin'; | ||
|
||
function Auth() { | ||
return ( | ||
<div className="flex h-dvh w-full flex-col items-center justify-center gap-16"> | ||
<div className="flex flex-col items-center gap-6"> | ||
<img src={TicleCharacterBadge} alt="티클 캐릭터" width={150} height={150} /> | ||
<TicleLogo className="fill-primary" width={190} /> | ||
<span className="text-head3 text-alt">작은 지식이 모여 큰 성장이 되는 곳</span> | ||
</div> | ||
<main className="flex flex-col items-center gap-4"> | ||
<OAuthLogin type="github" /> | ||
<OAuthLogin type="google" /> | ||
<GuestLogin /> | ||
</main> | ||
</div> | ||
); | ||
} | ||
|
||
export default Auth; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
import { createFileRoute, Link } from '@tanstack/react-router'; | ||
import { createFileRoute } from '@tanstack/react-router'; | ||
|
||
import Auth from '@/components/auth'; | ||
|
||
export const Route = createFileRoute('/auth/oauth')({ | ||
component: RouteComponent, | ||
}); | ||
|
||
function RouteComponent() { | ||
return ( | ||
<div className="flex"> | ||
OAuth 로그인 | ||
<Link to="/auth/login" className="border border-main p-5"> | ||
로컬 로그인 | ||
</Link> | ||
</div> | ||
); | ||
return <Auth />; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q:
cors 에러가 발생한다면
main.ts
에서 cors 설정을 진행해주면 되는 것 아닌가요? 메서드를 변경한 이유가 있을까요?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cors 설정을 해도 해결되지 않는 문제였습니다. 잠깐 알아보니 상당히 복잡하더라구요... 일단 로그인이 지금 저희가 집중해야할 중요한 부분은 아니라고 생각해서 빠른 조치를 취하게 되었습니다. 현재 로그인 방식이 GET에 어울리기도 하구요..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.milk717.com/gomterview-2
우연히 발견한게 또 곰터뷰 개발자분의 아티클인데 ㅋㅋㅋ 상당한 트러블 슈팅이 있었던것으로 보입니다 흠 이 부분을 집중해서 해결해봐야할지 고민이 됩니다...