박권수

feat. token logic change : cookie -> token authorization cause : native app

...@@ -68,7 +68,8 @@ exports.login = async(ctx) => { ...@@ -68,7 +68,8 @@ exports.login = async(ctx) => {
68 68
69 ctx.status = 200; 69 ctx.status = 200;
70 ctx.body = { 70 ctx.body = {
71 - userId 71 + userId,
72 + token
72 }; 73 };
73 74
74 }; 75 };
......
...@@ -7,8 +7,8 @@ const jwt = require('jsonwebtoken'); ...@@ -7,8 +7,8 @@ const jwt = require('jsonwebtoken');
7 7
8 //약병 등록 8 //약병 등록
9 exports.bottleConnect = async(ctx) => { 9 exports.bottleConnect = async(ctx) => {
10 - const token = ctx.cookies.get('access_token'); 10 + const token = ctx.req.headers.authorization;
11 - if(!token) { 11 + if(!token || !token.length) {
12 ctx.status = 401; 12 ctx.status = 401;
13 return; 13 return;
14 } 14 }
...@@ -55,8 +55,8 @@ exports.bottleConnect = async(ctx) => { ...@@ -55,8 +55,8 @@ exports.bottleConnect = async(ctx) => {
55 55
56 //약병 등록 해제 56 //약병 등록 해제
57 exports.bottleDisconnect = async(ctx) => { 57 exports.bottleDisconnect = async(ctx) => {
58 - const token = ctx.cookies.get('access_token'); 58 + const token = ctx.req.headers.authorization;
59 - if(!token) { 59 + if(!token || !token.length) {
60 ctx.status = 401; 60 ctx.status = 401;
61 return; 61 return;
62 } 62 }
...@@ -90,8 +90,8 @@ exports.bottleDisconnect = async(ctx) => { ...@@ -90,8 +90,8 @@ exports.bottleDisconnect = async(ctx) => {
90 90
91 //약병 정보를 조회 -> 약병에 현재 데이터를 요청한다. message : req 91 //약병 정보를 조회 -> 약병에 현재 데이터를 요청한다. message : req
92 exports.lookupInfo = async(ctx) => { 92 exports.lookupInfo = async(ctx) => {
93 - const token = ctx.cookies.get('access_token'); 93 + const token = ctx.req.headers.authorization;
94 - if(!token) { 94 + if(!token || !token.length) {
95 ctx.status = 401; 95 ctx.status = 401;
96 return; 96 return;
97 } 97 }
...@@ -124,8 +124,8 @@ exports.lookupInfo = async(ctx) => { ...@@ -124,8 +124,8 @@ exports.lookupInfo = async(ctx) => {
124 124
125 //약병의 ID를 찾아서 약의 정보를 등록 : Post 125 //약병의 ID를 찾아서 약의 정보를 등록 : Post
126 exports.setMedicine = async(ctx) => { 126 exports.setMedicine = async(ctx) => {
127 - const token = ctx.cookies.get('access_token'); 127 + const token = ctx.req.headers.authorization;
128 - if(!token) { 128 + if(!token || !token.length) {
129 ctx.status = 401; 129 ctx.status = 401;
130 return; 130 return;
131 } 131 }
...@@ -164,8 +164,8 @@ exports.setMedicine = async(ctx) => { ...@@ -164,8 +164,8 @@ exports.setMedicine = async(ctx) => {
164 164
165 //로그인한 유저의 약병 리스트 가져오기 165 //로그인한 유저의 약병 리스트 가져오기
166 exports.getBottleList = async(ctx) => { 166 exports.getBottleList = async(ctx) => {
167 - const token = ctx.cookies.get('access_token'); 167 + const token = ctx.req.headers.authorization;
168 - if(!token) { 168 + if(!token || !token.length) {
169 ctx.status = 401; 169 ctx.status = 401;
170 return; 170 return;
171 } 171 }
......
...@@ -5,8 +5,8 @@ const DataProcess = require('../../lib/DataProcess'); ...@@ -5,8 +5,8 @@ const DataProcess = require('../../lib/DataProcess');
5 const jwt = require('jsonwebtoken'); 5 const jwt = require('jsonwebtoken');
6 6
7 exports.hubConnect = async (ctx) => { 7 exports.hubConnect = async (ctx) => {
8 - const token = ctx.cookies.get('access_token'); 8 + const token = ctx.req.headers.authorization;
9 - if(!token) { 9 + if(!token || !token.length) {
10 ctx.status = 401; 10 ctx.status = 401;
11 return; 11 return;
12 } 12 }
...@@ -40,15 +40,14 @@ exports.hubConnect = async (ctx) => { ...@@ -40,15 +40,14 @@ exports.hubConnect = async (ctx) => {
40 }; 40 };
41 41
42 exports.getHubList = async(ctx) => { 42 exports.getHubList = async(ctx) => {
43 - const token = ctx.cookies.get('access_token'); 43 + const token = ctx.req.headers.authorization;
44 - if(!token) { 44 + if(!token || !token.length) {
45 ctx.status = 401; 45 ctx.status = 401;
46 return; 46 return;
47 } 47 }
48 48
49 const { userId } = jwt.verify(token, process.env.JWT_SECRET); 49 const { userId } = jwt.verify(token, process.env.JWT_SECRET);
50 const hubList = await Hub.find({ userId }); 50 const hubList = await Hub.find({ userId });
51 - console.log(hubList)
52 if(!hubList || !hubList.length) { 51 if(!hubList || !hubList.length) {
53 ctx.status = 404; 52 ctx.status = 404;
54 return; 53 return;
...@@ -59,8 +58,8 @@ exports.getHubList = async(ctx) => { ...@@ -59,8 +58,8 @@ exports.getHubList = async(ctx) => {
59 }; 58 };
60 59
61 exports.hubDisconnect = async(ctx) => { 60 exports.hubDisconnect = async(ctx) => {
62 - const token = ctx.cookies.get('access_token'); 61 + const token = ctx.req.headers.authorization;
63 - if(!token) { 62 + if(!token || !token.length) {
64 ctx.status = 401; 63 ctx.status = 401;
65 return; 64 return;
66 } 65 }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
2 const Medicine = require('../../models/medicine'); 2 const Medicine = require('../../models/medicine');
3 3
4 exports.medicineSearch = async(ctx) => { 4 exports.medicineSearch = async(ctx) => {
5 - const token = ctx.cookies.get('access_token'); 5 + const token = ctx.req.headers.authorization;
6 - if(!token) { 6 + if(!token || !token.length) {
7 ctx.status = 401; 7 ctx.status = 401;
8 return; 8 return;
9 } 9 }
...@@ -29,8 +29,8 @@ exports.medicineSearch = async(ctx) => { ...@@ -29,8 +29,8 @@ exports.medicineSearch = async(ctx) => {
29 } 29 }
30 30
31 exports.medicineGet = async(ctx) => { 31 exports.medicineGet = async(ctx) => {
32 - const token = ctx.cookies.get('access_token'); 32 + const token = ctx.req.headers.authorization;
33 - if(!token) { 33 + if(!token || !token.length) {
34 ctx.status = 401; 34 ctx.status = 401;
35 return; 35 return;
36 } 36 }
......