-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from DDD-Community/feature/77
[Feature/77] 로그인/회원가입 서버연결, 프로필 수정
- Loading branch information
Showing
14 changed files
with
216 additions
and
101 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { auth } from '@/auth' | ||
import KakaoIcon from 'public/icons/kakaoWbg.svg' | ||
|
||
const Email = async () => { | ||
const session = await auth() | ||
return ( | ||
<div className="mb-6 flex w-[264px] items-center border-b border-gray-950"> | ||
<div className="mr-2"> | ||
<KakaoIcon /> | ||
</div> | ||
<div className="flex-1 bg-transparent p-1 text-gray-400 outline-none"> | ||
{session?.user?.email} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Email |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use client' | ||
|
||
import Button from '@/components/Button' | ||
import { useSession } from 'next-auth/react' | ||
import { ReactNode, useState } from 'react' | ||
import NicknameInput from '@/components/TextInput/NicknameInput' | ||
import Title from './Title' | ||
|
||
const NicknameForm = ({ children }: { children: ReactNode }) => { | ||
const { data: session, update } = useSession() | ||
const [newName, setNewName] = useState<string>(session?.user?.name || '') | ||
const [hasError, setHasError] = useState(false) | ||
|
||
const updateNickname = async () => { | ||
update({ | ||
name: newName, | ||
}) | ||
} | ||
|
||
return ( | ||
<div className="mt-9 flex flex-1 flex-col px-10"> | ||
<div className="mx-auto w-[256px] flex-1"> | ||
<Title>닉네임</Title> | ||
<NicknameInput | ||
value={newName} | ||
setValue={setNewName} | ||
setHasError={setHasError} | ||
/> | ||
{children} | ||
</div> | ||
<Button | ||
size="lg" | ||
onClick={updateNickname} | ||
className="mb-10 mt-auto w-full" | ||
disabled={ | ||
session?.user?.name === newName || newName.length === 0 || hasError | ||
} | ||
> | ||
저장 | ||
</Button> | ||
</div> | ||
) | ||
} | ||
|
||
export default NicknameForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ReactNode } from 'react' | ||
|
||
const Title = ({ children }: { children: ReactNode }) => ( | ||
<h1 className="mb-3 text-lg font-semiBold">{children}</h1> | ||
) | ||
|
||
export default Title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use client' | ||
|
||
import { Dispatch, ReactNode, SetStateAction, useEffect, useState } from 'react' | ||
import { useSession } from 'next-auth/react' | ||
import TextInput from '.' | ||
|
||
const MAX_NICKNAME_LENGTH = 10 | ||
|
||
interface NicknameInputProps { | ||
value: string | ||
setValue: Dispatch<SetStateAction<string>> | ||
setHasError: Dispatch<SetStateAction<boolean>> | ||
icon?: ReactNode | ||
} | ||
|
||
const NicknameInput = ({ | ||
value, | ||
setValue, | ||
setHasError, | ||
icon = '', | ||
}: NicknameInputProps) => { | ||
const [errorMessage, setErrorMessage] = useState('') | ||
|
||
const { data: session } = useSession() | ||
|
||
useEffect(() => { | ||
if (session) { | ||
setValue(session.user!.name!) | ||
} | ||
}, [session]) | ||
|
||
useEffect(() => { | ||
setHasError(errorMessage.length > 0) | ||
}, [errorMessage]) | ||
|
||
const validateNickname = (name: string) => { | ||
if (name.length > MAX_NICKNAME_LENGTH) { | ||
setErrorMessage(`${MAX_NICKNAME_LENGTH}자 미만으로 입력해주세요`) | ||
return | ||
} | ||
|
||
const regex = /^[가-힣ㄱ-ㅎㅏ-ㅣa-zA-Z0-9]*$/ | ||
if (!regex.test(value)) { | ||
setErrorMessage('국문, 영문, 숫자만 입력 가능해요.') | ||
return | ||
} | ||
setErrorMessage('') | ||
} | ||
|
||
useEffect(() => { | ||
validateNickname(value) | ||
}, [value]) | ||
|
||
const onInput = (name: string) => { | ||
setValue(name) | ||
} | ||
return ( | ||
<TextInput | ||
errorMessage={errorMessage} | ||
description={`${value.length}/${MAX_NICKNAME_LENGTH}자`} | ||
value={value} | ||
hasError={errorMessage.length > 0} | ||
setValue={onInput} | ||
icon={icon} | ||
/> | ||
) | ||
} | ||
|
||
export default NicknameInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,10 @@ | ||
import { GetAccessTokenPayload, Token } from '@/types' | ||
// import { post } from './base' | ||
import { SignInPayload, User } from '@/types' | ||
import { post } from './base' | ||
|
||
type GetTokenResponse = { | ||
isNewUser: boolean | ||
} & Token | ||
export const login = async (body: SignInPayload): Promise<User> => { | ||
const res = await post('/api/v1/oauth/sign-in', { | ||
body: JSON.stringify(body), | ||
}) | ||
|
||
export const getToken = async ({ | ||
account, | ||
user, | ||
}: GetAccessTokenPayload): Promise<GetTokenResponse> => { | ||
// const res = await post('/', { | ||
// body: JSON.stringify({ | ||
// account, | ||
// user, | ||
// }), | ||
// }) | ||
console.log(account, user) | ||
|
||
return { | ||
isNewUser: true, | ||
accessToken: 'AT', | ||
refreshToken: 'RT', | ||
} | ||
return res.data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.