Skip to content

Commit

Permalink
bigint and auth
Browse files Browse the repository at this point in the history
  • Loading branch information
kimploo committed Jan 4, 2024
1 parent 18e8ef0 commit 7cbbca8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"scripts": {
"dev": "dotenv -e .env.dev serverless offline",
"prod": "dotenv -e .env serverless offline",
"sls-deploy": "serverless deploy",
"sls-remove": "serverless remove",
"db-dev-push": "dotenv -e .env.dev prisma db push",
Expand Down
26 changes: 13 additions & 13 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,23 @@ async function main() {
},
});

const card = await prisma.card.create({
data: {
id: 1,
from: '테스트 from',
to: '테스트 to',
msg: '테스트 카드 1',
createdAt: new Date(0),
artworkId: 1,
artworkBackgroundId: artworkBackground.id,
artworkSnowFlakeId: artworkSnowFlake.id,
},
});
// const card = await prisma.card.create({
// data: {
// id: 1,
// from: '테스트 from',
// to: '테스트 to',
// msg: '테스트 카드 1',
// createdAt: new Date(0),
// artworkId: 1,
// artworkBackgroundId: artworkBackground.id,
// artworkSnowFlakeId: artworkSnowFlake.id,
// },
// });

console.log('artworks', artworks);
console.log('artworkSnowFlakes', artworkSnowFlake);
console.log('artworkBackground', artworkBackground);
console.log('card', card);
// console.log('card', card);
}
main()
.then(async () => {
Expand Down
10 changes: 5 additions & 5 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default {
try {
user = await prisma.user.update({
where: {
kakaoId: kakaoUserInfo.id,
kakaoId: BigInt(kakaoUserInfo.id),
},
data: {
name: kakaoUserInfo.properties?.nickname || null,
Expand Down Expand Up @@ -163,8 +163,8 @@ export default {
return res.status(400).json(e);
}

const kakaoId = kakaoUserInfo.id;
console.log('kakaoId', kakaoId?.toString());
const kakaoId = BigInt(kakaoUserInfo.id);
console.log('kakaoId', kakaoId);

try {
user = await prisma.user.update({
Expand Down Expand Up @@ -235,10 +235,10 @@ export default {
try {
user = await prisma.user.upsert({
where: {
kakaoId: kakaoUserInfo.id,
kakaoId: BigInt(kakaoUserInfo.id),
},
create: {
kakaoId: kakaoUserInfo.id,
kakaoId: BigInt(kakaoUserInfo.id),
name: kakaoUserInfo.properties?.nickname || null,
createdAt: new Date(),
updatedAt: new Date(),
Expand Down
2 changes: 1 addition & 1 deletion src/card/card.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default {
try {
user = await prisma.user.findUnique({
where: {
kakaoId: decoded?.id,
kakaoId: BigInt(decoded?.id),
},
});
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export const authFunc: RequestHandler = async (req, res, next) => {
try {
user = await prisma.user.upsert({
where: {
kakaoId: kakaoUserInfo.id,
kakaoId: BigInt(kakaoUserInfo.id),
},
create: {
kakaoId: kakaoUserInfo.id,
kakaoId: BigInt(kakaoUserInfo.id),
name: kakaoUserInfo.properties?.nickname || null,
createdAt: new Date(),
updatedAt: new Date(),
Expand Down
12 changes: 6 additions & 6 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ const cardRouter = express.Router();
const artworkRouter = express.Router();

const isDev = process.env.IS_OFFLINE;
const auth = isDev ? (_: any, __: any, next: () => any) => next() : authFunc;
// const auth = isDev ? (_: any, __: any, next: () => any) => next() : authFunc;

// authRouter.post('/', authController.auth);
loginRouter.get('/', authController.login);
logoutRouter.post('/', authController.logout);
authRouter.get('/', authController.auth);
artworkRouter.get('/', auth, artworkController.findMany);
cardRouter.get('/', auth, cardController.findMany);
artworkRouter.get('/', artworkController.findMany);
cardRouter.get('/', authFunc, cardController.findMany);
cardRouter.get('/:uuid', cardController.findOne);
cardRouter.post('/', auth, cardController.createOne);
cardRouter.put('/:id', auth, cardController.updateOne);
cardRouter.delete('/:id', auth, cardController.deleteOne);
cardRouter.post('/', authFunc, cardController.createOne);
cardRouter.put('/:id', authFunc, cardController.updateOne);
cardRouter.delete('/:id', authFunc, cardController.deleteOne);

export { authRouter, cardRouter, loginRouter, logoutRouter, artworkRouter };

0 comments on commit 7cbbca8

Please sign in to comment.