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 e24e308 commit ca74176
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 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
22 changes: 16 additions & 6 deletions packages/server/index.js
Original file line number Diff line number Diff line change
@@ -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 등으로 수정하기
Expand All @@ -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, () => {
Expand Down

0 comments on commit ca74176

Please sign in to comment.