박권수

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

......@@ -68,7 +68,8 @@ exports.login = async(ctx) => {
ctx.status = 200;
ctx.body = {
userId
userId,
token
};
};
......
......@@ -7,8 +7,8 @@ const jwt = require('jsonwebtoken');
//약병 등록
exports.bottleConnect = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
......@@ -55,8 +55,8 @@ exports.bottleConnect = async(ctx) => {
//약병 등록 해제
exports.bottleDisconnect = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
......@@ -90,8 +90,8 @@ exports.bottleDisconnect = async(ctx) => {
//약병 정보를 조회 -> 약병에 현재 데이터를 요청한다. message : req
exports.lookupInfo = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
......@@ -124,8 +124,8 @@ exports.lookupInfo = async(ctx) => {
//약병의 ID를 찾아서 약의 정보를 등록 : Post
exports.setMedicine = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
......@@ -164,8 +164,8 @@ exports.setMedicine = async(ctx) => {
//로그인한 유저의 약병 리스트 가져오기
exports.getBottleList = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
......
......@@ -5,8 +5,8 @@ const DataProcess = require('../../lib/DataProcess');
const jwt = require('jsonwebtoken');
exports.hubConnect = async (ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
......@@ -40,15 +40,14 @@ exports.hubConnect = async (ctx) => {
};
exports.getHubList = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
const { userId } = jwt.verify(token, process.env.JWT_SECRET);
const hubList = await Hub.find({ userId });
console.log(hubList)
if(!hubList || !hubList.length) {
ctx.status = 404;
return;
......@@ -59,8 +58,8 @@ exports.getHubList = async(ctx) => {
};
exports.hubDisconnect = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
......
......@@ -2,8 +2,8 @@
const Medicine = require('../../models/medicine');
exports.medicineSearch = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
......@@ -29,8 +29,8 @@ exports.medicineSearch = async(ctx) => {
}
exports.medicineGet = async(ctx) => {
const token = ctx.cookies.get('access_token');
if(!token) {
const token = ctx.req.headers.authorization;
if(!token || !token.length) {
ctx.status = 401;
return;
}
......