Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/(with-header-sidebar)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactNode } from 'react';
import SideBar from '@/components/SideBar';
import SideBar from '@/components/sidebar/SideBar';
import styles from './layout.module.css';
import MainContainer from '@/components/MainContainer';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect, useCallback } from 'react';
import { AxiosResponse, AxiosError } from 'axios';
import axiosInstance from '../utils/axiosInstance';
import axiosInstance from '../_utils/axiosInstance';

type UseApiFetchReturnType<T> = {
data: T | null;
Expand Down Expand Up @@ -50,7 +50,7 @@ export default function useApi<
} finally {
setLoading(false);
}
}, [url, options.method, options.params, options.body]);
}, [url, JSON.stringify(options)]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ—¬κΈ°μ„œ JSON.stringify() 이것을 μ‚¬μš©ν•˜μ‹  μ˜λ„κ°€ λ­”κ°€μš”???
κ·Έλƒ₯ options둜 λ„£μœΌλ©΄ μ•ˆλ˜λ‚˜μš”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@najitwo λ””μ½”μ•ˆλ¨222....
이거.. option듀이 항상 λ‹€λ₯Έκ°’을 κ°€μ§€κ³ μ˜€λŠ”κ±°λΌμ„œ λ¬΄ν•œλ‘œλ”© λ˜λ”λΌκ΅¬μš”...


useEffect(() => {
fetchData();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface Dashboard {
export interface Dashboard {
id: number;
title: string;
color: string;
Expand All @@ -8,14 +8,14 @@ interface Dashboard {
createdByMe: boolean;
}

interface GetDashboardsRequestParams {
export interface GetDashboardsRequestParams {
navigationMethod: 'infiniteScroll' | 'pagination';
cursorId?: number;
page?: number;
size?: number;
}

interface GetDashboardsResponse {
export interface GetDashboardsResponse {
dashboards: Dashboard[];
totalCount: number;
cursorId: number | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const axiosInstance: AxiosInstance = axios.create({

axiosInstance.interceptors.request.use(
(config) => {
const token = 'your-token-here'; // TODO: Add token
const token =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NDgwNCwidGVhbUlkIjoiMTAtMSIsImlhdCI6MTczMTcyMzkwNywiaXNzIjoic3AtdGFza2lmeSJ9.k8FqEAl7DbhwxhJNAkkMq8lYrgStN-9I3xrsR0cYm2c'; // TODO: Add token
if (token) {
config.headers['Authorization'] = `Bearer ${token}`;
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/not-found.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.title {
color: skyblue;
}
5 changes: 5 additions & 0 deletions src/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styles from './not-found.module.css';

export default function NotFoundPage() {
return <div className={styles.title}>Page not found!!</div>;
}
2 changes: 1 addition & 1 deletion src/components/MainContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode } from 'react';
import Header from './header/Header';
import styles from './MainContainer.module.css';
import Header from './Header';

export default function MainContainer({ children }: { children: ReactNode }) {
return (
Expand Down
19 changes: 0 additions & 19 deletions src/components/SideBar.module.css

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
'use client';
import { usePathname } from 'next/navigation';
import Image from 'next/image';
import Button from './Button';
import Button from '../Button';
import UserInfo from './UserInfo';
import styles from './Header.module.css';

interface HeaderProps {
component: React.ComponentType;
component?: React.ComponentType;
}

export default function Header({ component: Component }: HeaderProps) {
const pathname = usePathname();

return (
<header className={styles.header}>
<span className={styles.title}>λ‚΄ λŒ€μ‹œλ³΄λ“œ</span>
<h2 className={styles.title}>λ‚΄ λŒ€μ‹œλ³΄λ“œ</h2>
<div className={styles.buttonContainer}>
<Button className={styles.button}>
<Image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client';

import type { User } from '@/app/(with-header-sidebar)/mydashboard/types/user';
import styles from './UserInfo.module.css';
import type { User } from '@/app/(with-header-sidebar)/mydashboard/_types/user';
import Image from 'next/image';
import useWindowSize from '@/app/(with-header-sidebar)/mydashboard/hooks/useWindowSize';
import useWindowSize from '@/app/(with-header-sidebar)/mydashboard/_hooks/useWindowSize';
import { useState, useEffect } from 'react';
import UserInfoSkeleton from './skeleton/UserInfoSkeleton';
import UserInfoSkeleton from '../skeleton/UserInfoSkeleton';
import styles from './UserInfo.module.css';

const user: User = {
id: 1,
Expand Down
10 changes: 10 additions & 0 deletions src/components/sidebar/Dashboards.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.dashBoards {
display: flex;
flex-direction: column;
justify-content: center;
gap: 6px;
}

.active {
color: salmon;
}
31 changes: 31 additions & 0 deletions src/components/sidebar/Dashboards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import type { GetDashboardsResponse } from '@/app/(with-header-sidebar)/mydashboard/_types/dashboards';
import styles from './Dashboards.module.css';
import useApi from '@/app/(with-header-sidebar)/mydashboard/_hooks/useApi';

export default function Dashboards() {
const pathname = usePathname();

const { data } = useApi<GetDashboardsResponse>('/dashboards', {
method: 'GET',
params: { navigationMethod: 'infiniteScroll', page: 1, size: 10 },
});

const dashboards = data?.dashboards;

return (
<div className={styles.dashBoards}>
{dashboards &&
dashboards.map((board) => (
<Link
key={board.id}
href={`/dashboard/${board.id}`}
className={`link ${pathname === '/dashboard/' + board.id ? styles.active : ''}`}
>
{board.title}
</Link>
))}
</div>
);
}
46 changes: 46 additions & 0 deletions src/components/sidebar/SideBar.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.sideBar {
display: flex;
flex-direction: column;
align-items: center;
gap: 30px;
}

.logo {
background-color: transparent;
text-align: left;
}

.addDashBoardsContainer {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
}

.addDashBoardsTitle {
display: none;
}

.addButton {
background-color: transparent;
width: 20px;
}

@media screen and (min-width: 768px) {
.sideBar {
min-width: 155px;
}

.addDashBoardsTitle {
display: inline;
color: var(--gray-500);
font-size: 12px;
font-weight: 600;
}
}

@media screen and (min-width: 1199px) {
.sideBar {
min-width: 300px;
}
}
Original file line number Diff line number Diff line change
@@ -1,55 +1,47 @@
'use client';

import Link from 'next/link';
import { usePathname } from 'next/navigation';
import Image from 'next/image';
import Button from './Button';
import useWindowSize from '@/app/(with-header-sidebar)/mydashboard/hooks/useWindowSize';
import Button from '../Button';
import useWindowSize from '@/app/(with-header-sidebar)/mydashboard/_hooks/useWindowSize';
import Dashboards from './DashBoards';
import styles from './SideBar.module.css';

export default function SideBar() {
const pathname = usePathname();
const { isMobile } = useWindowSize();

return (
<div className={styles.sideBar}>
<Button aria-label="ν™ˆνŽ˜μ΄μ§€ 이동" className={styles.button}>
<Button aria-label="ν™ˆνŽ˜μ΄μ§€ 이동" className={styles.logo}>
{isMobile ? (
<Image
src="/images/logo_small.svg"
alt="둜고 ν™ˆνŽ˜μ΄μ§€μ΄λ™"
width={24}
height={27}
priority
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ½˜μ†”μ— priorityλ„£μœΌλΌκ³  μ›Œλ”©λ– κ°€μ§€κ³  걍 λ„£μ—ˆμ–΄μš”

/>
) : (
<Image
src="/images/logo_large.svg"
alt="둜고 ν™ˆνŽ˜μ΄μ§€μ΄λ™"
width={109}
height={33}
priority
/>
)}
</Button>
<Button aria-label="λŒ€μ‹œλ³΄λ“œ μΆ”κ°€ν•˜κΈ°" className={styles.button}>
<Image
src="/icons/add_box.svg"
alt="λŒ€μ‹œλ³΄λ“œ μΆ”κ°€ν•˜κΈ°"
width={20}
height={20}
/>
</Button>
<Link
href={'/dashboard/1'}
className={`link ${pathname === '/dashboard/1' ? styles.active : ''}`}
>
O
</Link>
<Link
href={'/dashboard/2'}
className={`link ${pathname === '/dashboard/2' ? styles.active : ''}`}
>
O
</Link>
<div className={styles.addDashBoardsContainer}>
<span className={styles.addDashBoardsTitle}>Dash Boards</span>
<Button aria-label="λŒ€μ‹œλ³΄λ“œ μΆ”κ°€ν•˜κΈ°" className={styles.addButton}>
<Image
src="/icons/add_box.svg"
alt="λŒ€μ‹œλ³΄λ“œ μΆ”κ°€ν•˜κΈ°"
width={20}
height={20}
/>
</Button>
</div>
<Dashboards />
</div>
);
}
24 changes: 24 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NextRequest, NextResponse } from 'next/server';

export function middleware(request: NextRequest) {
const user = request.cookies.get('user'); // TODO get token
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미듀웨어 μ‚¬μš©ν•˜λ €λ©΄ set cookie headerλ₯Ό μ„€μ •ν•΄μ•Όκ² λ„€μš” πŸ€”

Copy link
Collaborator Author

@devmanta devmanta Nov 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@najitwo μ•„..!
κ·ΈλŸ¬λ„€μš” μƒκ°ν•΄λ³΄λ‹ˆκΉ.. λΈŒλΌμš°μ € 가기전이라 accessToken μ»¨ν…μŠ€νŠΈμ—μ„œ λͺ»κ°€μ Έμ˜€λ„€μš”...? (λ§žλ‚˜..)
μ—„... 그럼 이거 λͺ»μ“°λŠ”λ°..

Copy link
Collaborator Author

@devmanta devmanta Nov 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•„
const authHeader = request.headers.get('authorization');
μ΄λŸ°μ‹μœΌλ‘œ ν—€λ”μ—μ„œ κ°€μ Έμ˜€λ©΄λ˜λ‚˜λ΄μš”!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 apiκ°€ set cookie header κ°€ λ˜μžˆλŠ”κ²Œ μ•„λ‹ˆλΌκ°€μ§€κ³ ...μ•„λ§ˆ λ§Œλ“€μ–΄μ•Ό λ κ±°μ—μš”!!
둜그인 λ‘œμ§μ— cookies().set("accessToken", asdjaskdjaskd) μš”λŸ°μ‹μœΌλ‘œ

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
이게 둜그인 응닡 헀더인데 μ–΄λ–€ 값을 λ§μ”€ν•˜μ‹œλŠ” κ±΄κ°€μš”???

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•„ μ•„λ‹™λ‹ˆλ‹€ μ œκ°€ 잘λͺ»μƒκ°ν–ˆμ–΄μš”
μΏ ν‚€ μ„€μ • μ§μ ‘ν•˜λŠ”κ±΄ 별둠데... γ… 

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건... set cookie μ•ˆν•΄μ€€ λ°±μ—”λ“œ νƒ“μœΌλ‘œ 🀣


// const restrictedPaths = ['/dashboard', '/mypage', '/mydashboard'];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 μ§„μ§œ μ μš©λ˜μ–΄μ•Όν•˜λŠ” μ½”λ“œμΈλ° μ§€κΈˆ κ°œλ°œμ€‘μ΄λΌ μ£Όμ„μ²˜λ¦¬ ν•΄λ†¨μŠ΅λ‹ˆλ‹€

const restrictedPaths = ['/test'];

if (
restrictedPaths.some((path) => request.nextUrl.pathname.startsWith(path))
) {
if (!user) {
// return NextResponse.redirect(new URL('/login', request.url));
return NextResponse.redirect(new URL('/', request.url));
}
}

return NextResponse.next();
}

export const config = {
// matcher: ['/dashboard/:path*', '/mypage', '/mydashboard/:path*'],
matcher: ['/test'],
};