File tree 6 files changed +64
-0
lines changed
6 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1
1
import axios from 'axios' ;
2
2
3
+ const accessToken =
4
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImNiN2ZiMTExZTp1c2VyMyIsImlhdCI6MTY5OTUzMzExMiwiZXhwIjoxNzAwMTM3OTEyfQ.4eslctzcBGQAwkcKT97IbF0i-9-MZ0kvhjY4A6sK8Wo' ;
5
+
3
6
const instance = axios . create ( {
4
7
baseURL : 'https://fastcampus-chat.net' ,
5
8
// 여기에 공통 설정을 추가할 수 있습니다.
6
9
headers : {
7
10
'Content-Type' : 'application/json' ,
11
+ Authorization : `Bearer ${ accessToken } ` ,
8
12
serverId : process . env . NEXT_PUBLIC_API_KEY ,
9
13
} ,
10
14
} ) ;
Original file line number Diff line number Diff line change
1
+ import instance from './axios' ;
2
+
3
+ const chatListAPI = {
4
+ // 로그인
5
+ getAllChatList ( ) {
6
+ return instance . get ( '/chat/all' ) ;
7
+ } ,
8
+ // 회원가입
9
+ getMyChatList ( ) {
10
+ return instance . get ( '/chat' ) ;
11
+ } ,
12
+ } ;
13
+
14
+ export default chatListAPI ;
Original file line number Diff line number Diff line change
1
+ import { useState , useEffect } from 'react' ;
2
+ import Link from 'next/link' ;
3
+ import chatListAPI from '../../apis/chatListAPI' ;
4
+
5
+ export default function AllChatList ( ) {
6
+ const [ allChatList , setAllChatList ] = useState ( [ ] ) ;
7
+ const getAllChat = async ( ) => {
8
+ const chatAllList = await chatListAPI . getAllChatList ( ) ;
9
+ setAllChatList ( chatAllList . data . chats ) ;
10
+ } ;
11
+ useEffect ( ( ) => {
12
+ getAllChat ( ) ;
13
+ } , [ ] ) ;
14
+ return (
15
+ < >
16
+ { allChatList . map ( chat => (
17
+ < Link href = { `/chat/${ chat . id } ` } key = { chat . id } >
18
+ < div > { chat . name } </ div >
19
+ </ Link >
20
+ ) ) }
21
+ </ >
22
+ ) ;
23
+ }
Original file line number Diff line number Diff line change
1
+ import { useState , useEffect } from 'react' ;
2
+ import Link from 'next/link' ;
3
+ import chatListAPI from '../../apis/chatListAPI' ;
4
+
5
+ export default function MyChatList ( ) {
6
+ const [ myChatList , setMyChatList ] = useState ( [ ] ) ;
7
+ const getMyChat = async ( ) => {
8
+ const ChatMyList = await chatListAPI . getMyChatList ( ) ;
9
+ setMyChatList ( ChatMyList . data . chats ) ;
10
+ } ;
11
+ useEffect ( ( ) => {
12
+ getMyChat ( ) ;
13
+ } , [ ] ) ;
14
+ return (
15
+ < >
16
+ { myChatList . map ( chat => (
17
+ < Link href = { `/chat/${ chat . id } ` } key = { chat . id } >
18
+ < div > { chat . name } </ div >
19
+ </ Link >
20
+ ) ) }
21
+ </ >
22
+ ) ;
23
+ }
You can’t perform that action at this time.
0 commit comments