From ca74176834fd2f784778d898eedbaad365232807 Mon Sep 17 00:00:00 2001 From: hwna00 Date: Mon, 25 Sep 2023 14:40:43 +0900 Subject: [PATCH] =?UTF-8?q?Feat(server):=20=ED=8C=8C=EC=9D=B4=EC=96=B4?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EC=BB=A4=EC=8A=A4=ED=85=80=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=A0=9C=EC=9E=91=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fbCreateCustomToken ref: #67 --- packages/apps/user/src/api.js | 12 ------------ packages/server/index.js | 22 ++++++++++++++++------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/apps/user/src/api.js b/packages/apps/user/src/api.js index f89de9e4..c7388313 100644 --- a/packages/apps/user/src/api.js +++ b/packages/apps/user/src/api.js @@ -1,22 +1,10 @@ import axios from 'axios'; import { getUserImage } from '../firebase'; -//TODO: 요청 시 access_token or refresh_token 보내는 기능 추가 const instance = axios.create({ baseURL: 'http://localhost:3000/api', - //TODO: 필요한 경우에만 withCredentials 추가하도록 수정 - // withCredentials: true, }); -export const createUser = async data => { - try { - const user = await instance.post('/auth/create-user', data); - return user; - } catch (error) { - console.log(error); - } -}; - export const getMe = async () => { const { user } = await instance.get(`/users/me`); if (!user) { diff --git a/packages/server/index.js b/packages/server/index.js index 7515366c..5dd22539 100644 --- a/packages/server/index.js +++ b/packages/server/index.js @@ -1,5 +1,6 @@ const express = require('express'); const cors = require('cors'); +const fbAdmin = require('./config/fbAdmin'); const app = express(); const port = 3000; //TODO: .env 파일의 PORT 이름 DBPORT 등으로 수정하기 @@ -8,13 +9,22 @@ app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.use(cors({ origin: 'http://localhost:8080' })); -app.get('/', (req, res) => { - console.log('get /'); -}); +const fbCreateCustomToken = uid => { + fbAdmin + .auth() + .createCustomToken(uid) + .then(customToken => { + return customToken; + }) + .catch(error => { + console.log('Error creating custom token:', error); + }); +}; -app.post('/api/auth/create-user', (req, res) => { - console.log(req.body); - //TODO: firebase로부터 온 요쳥이라면 JWT 토큰 생성하기 +app.get('/api/users/me', (req, res) => { + console.log('me'); + //TODO: DB로부터 사용자 정보 검색 + res.json({}); }); app.listen(port, () => {