Skip to content

Commit

Permalink
로그인시 블로그 생성여부 확인
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaeyeon1 committed Nov 29, 2023
1 parent f61fb95 commit bda325b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 49 deletions.
11 changes: 11 additions & 0 deletions client/src/api/blog-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,14 @@ export const useGetSidebarQuery = (params: ISidebar) => {
});
return { data, isLoading, error };
};

export const getIsNewBlogApi = async () => {
const { data } = await defaultInstance.get('/is/new/blog');

return data;
};

export const useGetIsNewBlogQuery = () => {
const { isLoading, error, data } = useQuery([`isNewBlog`], () => getIsNewBlogApi(), {});
return { data, isLoading, error };
};
6 changes: 6 additions & 0 deletions client/src/app/mypage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ function page() {
setImageSrc(userData?.thumbnail ?? '');
}, [userData, isUserInfoEdit]);

useEffect(() => {
setName(userData?.nickName ?? '');
setIntroduction(userData?.introduction ?? '');
setImageSrc(userData?.thumbnail ?? '');
}, []);

const onUpload = async (e: any) => {
const file = e.target.files[0];
const reader: any = new FileReader();
Expand Down
110 changes: 63 additions & 47 deletions client/src/app/oauth2/redirect/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use client';
import { useGetIsNewBlogQuery } from '@/api/blog-api';
import { PostMakeAccountApi } from '@/api/makeAccount-api';
import CenterContent from '@/components/Layout/CenterContent';
import { TextField } from '@mui/material';
Expand All @@ -7,6 +8,7 @@ import { Stack } from '@mui/material';
import { useMutation } from '@tanstack/react-query';
import { useSearchParams } from 'next/navigation';
import { useRouter } from 'next/navigation';
import { enqueueSnackbar } from 'notistack';
import React, { useEffect, useState } from 'react';

const Page = () => {
Expand All @@ -15,6 +17,7 @@ const Page = () => {
const [blogUrl, setBlogUrl] = useState<string>('');
const [blogName, setBlogName] = useState<string>('');
const [nickname, setNickname] = useState<string>('');
const { data, isLoading } = useGetIsNewBlogQuery();

const postMakeAccountCreateQuery = useMutation(PostMakeAccountApi, {
onSuccess: () => router.push('/collect'),
Expand All @@ -30,67 +33,80 @@ const Page = () => {
postMakeAccountCreateQuery.mutate(newAccountBody);
};

useEffect(() => {
if (data) {
router.push('/collect');
enqueueSnackbar({ message: '로그인 성공하였습니다.', variant: 'success' });
}
}, [data]);

useEffect(() => {
const getTokenValue = params.get('token');
const error = params.get('error');

if (getTokenValue) {
localStorage.setItem('token', getTokenValue);
console.log(getTokenValue);
} else {
console.log(error);
enqueueSnackbar({ message: '로그인에 실패하였습니다.', variant: 'error' });
}
}, [params]);

return (
<CenterContent>
<Stack width="300px" margin="auto" flexDirection="column" alignItems="center">
<TextField
required
fullWidth
sx={{ marginBottom: '5px' }}
id="outlined-basic"
label="blog URL"
variant="outlined"
value={blogUrl}
onChange={(e) => {
setBlogUrl(e.target.value);
}}
/>
<Stack fontSize="10px" color="red" marginBottom="15px">
*블로그 URL은 수정할 수 없으니 신중히 적어주세요.
</Stack>
<TextField
required
fullWidth
sx={{ marginBottom: '30px' }}
id="outlined-basic"
label="이름"
variant="outlined"
value={blogName}
onChange={(e) => {
setBlogName(e.target.value);
}}
/>
<TextField
required
fullWidth
sx={{ marginBottom: '5px' }}
id="outlined-basic"
label="닉네임"
variant="outlined"
value={nickname}
onChange={(e) => {
setNickname(e.target.value);
}}
/>
<Stack fontSize="10px" color="red" marginBottom="15px">
*닉네임이 블로그 주소에 반영 됩니다.
{!isLoading && (
<Stack width="300px" margin="auto" flexDirection="column" alignItems="center">
<TextField
required
fullWidth
sx={{ marginBottom: '5px' }}
id="outlined-basic"
label="blog URL"
variant="outlined"
value={blogUrl}
onChange={(e) => {
setBlogUrl(e.target.value);
}}
/>
<Stack fontSize="10px" color="red" marginBottom="15px">
*블로그 URL은 수정할 수 없으니 신중히 적어주세요.
</Stack>
<TextField
required
fullWidth
sx={{ marginBottom: '30px' }}
id="outlined-basic"
label="이름"
variant="outlined"
value={blogName}
onChange={(e) => {
setBlogName(e.target.value);
}}
/>
<TextField
required
fullWidth
sx={{ marginBottom: '5px' }}
id="outlined-basic"
label="닉네임"
variant="outlined"
value={nickname}
onChange={(e) => {
setNickname(e.target.value);
}}
/>
<Stack fontSize="10px" color="red" marginBottom="15px">
*닉네임이 블로그 주소에 반영 됩니다.
</Stack>
<Button
fullWidth
sx={{ height: '50px' }}
variant="outlined"
onClick={() => postOnClick()}>
입력
</Button>
</Stack>
<Button fullWidth sx={{ height: '50px' }} variant="outlined" onClick={() => postOnClick()}>
입력
</Button>
</Stack>
)}
</CenterContent>
);
};
Expand Down
4 changes: 2 additions & 2 deletions client/src/constant/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const getCurrentThemeClass = (
export const API_BASE_URL =
'http://glogglogglog-env.eba-fuksumx7.ap-northeast-2.elasticbeanstalk.com';

// export const OAUTH2_REDIRECT_URI = 'http://localhost:3000/oauth2/redirect';
export const OAUTH2_REDIRECT_URI = 'http://15.164.221.35:3000/oauth2/redirect';
export const OAUTH2_REDIRECT_URI = 'http://localhost:3000/oauth2/redirect';
// export const OAUTH2_REDIRECT_URI = 'http://15.164.221.35:3000/oauth2/redirect';

export const GITHUB_AUTH_URL =
API_BASE_URL + '/oauth2/authorization/github?redirect_uri=' + OAUTH2_REDIRECT_URI;

0 comments on commit bda325b

Please sign in to comment.