Skip to content

Commit

Permalink
feat: 통신 api 토큰 처리 #78
Browse files Browse the repository at this point in the history
  • Loading branch information
JeongYunMi committed Oct 23, 2023
1 parent 83efc0d commit 70a49af
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 deletions.
20 changes: 13 additions & 7 deletions src/apis/sendApi.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import axios from 'axios';
import { AUTH_KEY } from '../constants/authkey';
import httpService from '../constants/libs/httpService';
import { AUTH_KEY, } from '../constants/authkey';
import { SESSION_KEY } from '../constants/session';
import sessionStorageService from '../libs/sessionStorageService';
import authorization from '../libs/httpService';

let ck = `eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0YW1kNTk3MUBuYXZlci5jb20iLCJyb2xlcyI6Ik1BTkFHRVIiLCJpYXQiOjE2OTM4OTE1MzUsImV4cCI6MTY5Mzg5MzMzNX0.xvxGA-2tW3en2DKv-Q-ZaI38r4f2lNCO1M8kNSZwXhk`

export const sendApi = {
get: (url:string) => {
return axios.get(
`https://api.dessert-gallery.site${url}`,
// httpService.authorization(localStorageService.get(SESSION_ID))
httpService.authorization(ck)
);
console.log('sessionStorageService.get(SESSION_KEY', sessionStorageService.get(SESSION_KEY))
if(sessionStorageService.get(SESSION_KEY) !== null){
return axios.get(
`${AUTH_KEY.apiUrl}${url}`,
authorization(sessionStorageService.get(SESSION_KEY))
);
}else{
return axios.get(`${AUTH_KEY.apiUrl}${url}`);
}
},


Expand Down
6 changes: 3 additions & 3 deletions src/constants/authkey.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {
REACT_APP_API_URI,
NEXT_PUBLIC_API_URL,
} = process.env;

export const AUTH_KEY = {
apiUrl: REACT_APP_API_URI,
};
apiUrl: NEXT_PUBLIC_API_URL,
};
11 changes: 0 additions & 11 deletions src/constants/libs/httpService.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/constants/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const SESSION_KEY = 'JWTSessionStorage';
10 changes: 10 additions & 0 deletions src/libs/httpService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

const authorization = (token:string|null) => {
return {
headers: {
Authorization: `${token}`,
},
};
};

export default authorization;
13 changes: 13 additions & 0 deletions src/libs/sessionStorageService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const sessionStorageService = {
set: (key:string, value:string='') => {
return typeof window !== 'undefined' ? sessionStorage.setItem(key, value) : null;
},
get: (key:string = '')=> {
return typeof window !== 'undefined' ? sessionStorage.getItem(key) : null;
},
delete: (key:string = '') => {
return typeof window !== 'undefined' ? sessionStorage.removeItem(key) : null;
},
};

export default sessionStorageService;

0 comments on commit 70a49af

Please sign in to comment.