Skip to content

Commit

Permalink
Feat(server): 파이어베이스 커스텀 토큰 제작 함수 생성
Browse files Browse the repository at this point in the history
- fbCreateCustomToken

ref: #67
  • Loading branch information
hwna00 committed Sep 25, 2023
1 parent f587bec commit 4d7f49f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
12 changes: 0 additions & 12 deletions packages/apps/user/src/api.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
20 changes: 17 additions & 3 deletions packages/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const cors = require('cors');
const axios = require('axios');
require('dotenv').config();
const fbAdmin = require('./config/fbAdmin');

const app = express();
const port = 3000; //TODO: .env 파일의 PORT 이름 DBPORT 등으로 수정하기
Expand Down Expand Up @@ -61,9 +62,22 @@ app.get('/api/auth/naver-callback', async (req, res) => {
}
});

app.post('/api/auth/create-user', (req, res) => {
console.log(req.body);
//TODO: firebase로부터 온 요쳥이라면 JWT 토큰 생성하기
const fbCreateCustomToken = uid => {
fbAdmin
.auth()
.createCustomToken(uid)
.then(customToken => {
return customToken;
})
.catch(error => {
console.log('Error creating custom token:', error);
});
};

app.get('/api/users/me', (req, res) => {
console.log('me');
//TODO: DB로부터 사용자 정보 검색
res.json({});
});

app.listen(port, () => {
Expand Down

0 comments on commit 4d7f49f

Please sign in to comment.