Skip to content

Commit

Permalink
Merge pull request #160 from ttaerrim/login-status
Browse files Browse the repository at this point in the history
[Feat] 프론트엔드에서 로그인 사용자 판단
  • Loading branch information
ttaerrim authored Nov 23, 2023
2 parents fa9a9b9 + 98e9b04 commit aace6a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/frontend/src/pages/Main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ReactComponent as GoogleIcon } from '@/assets/icons/google.svg';
import { Button } from '@/components';
import { MAIN_IMAGE, URL } from '@/constants';
import { useUserAtom } from '@/stores';
import { getCookies } from '@/utils';

import * as styles from './index.css';

export function Main() {
const onClickGoogleLogin = () => {
window.location.href = `${URL.API}/auth/google/login`;
};
const [user] = useUserAtom();

const isLogin = getCookies('access_token');

return (
<div className={styles.container}>
Expand All @@ -22,7 +23,7 @@ export function Main() {
모락과 함께하세요
</div>
<div className={styles.login}>
{!user && (
{!isLogin && (
<Button
type="button"
theme="primary"
Expand Down
11 changes: 10 additions & 1 deletion app/frontend/src/services/morakAPI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import axios from 'axios';

import { URL } from '@/constants';
import { getCookies } from '@/utils';

const initialHeaders = {
'Content-Type': 'application/json',
Accept: 'application/json',
};
const headers = getCookies('access_token')
? { ...initialHeaders, Authorization: `Bearer ${getCookies('access_token')}` }
: initialHeaders;

export const morakAPI = axios.create({
baseURL: import.meta.env.DEV ? '' : URL.API,
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
headers,
});

0 comments on commit aace6a6

Please sign in to comment.