11import { CREATED , OK } from '@constants/http-status' ;
22import jwtAuthenticator from '@middlewares/jwt-authenticator' ;
3- import { PostLoginBody } from '@wabinar/api-types/auth' ;
3+ import { LoginResBody , PostLoginBody } from '@wabinar/api-types/auth' ;
44import asyncWrapper from '@utils/async-wrapper' ;
55import express , { Request , Response } from 'express' ;
6- import * as userService from '../user/service' ;
76import * as authService from './service' ;
87
98interface CookieOptions {
@@ -18,47 +17,44 @@ const router = express.Router();
1817router . get (
1918 '/' ,
2019 jwtAuthenticator ,
21- asyncWrapper ( async ( req : Request , res : Response ) => {
20+ asyncWrapper ( async ( req : Request , res : Response < LoginResBody > ) => {
2221 if ( ! req . user ) {
2322 res . status ( OK ) . send ( { user : req . user } ) ;
2423 return ;
2524 }
2625
27- // req.user가 존재하면 workspaceList를 같이 받아옴
2826 const { id : userId , name, avatarUrl } = req . user ;
2927
30- const workspaces = await userService . getWorkspaces ( userId ) ;
31-
3228 const user = { id : userId , name, avatarUrl } ;
3329
34- res . status ( OK ) . send ( { user, workspaces } ) ;
30+ res . status ( OK ) . send ( { user } ) ;
3531 } ) ,
3632) ;
3733
38- // authorized된 유저가 아닐 경우(위에서 !req.user조건으로 return 됨)
39- // OAuth 페이지에서 workspace로 이동(navigate)하게 되므로
40- // 로그인 하여 받아온 유저 정보로 workspace list 정보도 함께 받아온다.
4134router . post (
4235 '/login' ,
4336 jwtAuthenticator ,
44- asyncWrapper ( async ( req : Request < { } , { } , PostLoginBody > , res : Response ) => {
45- const { code } = req . body ;
37+ asyncWrapper (
38+ async (
39+ req : Request < { } , { } , PostLoginBody > ,
40+ res : Response < LoginResBody > ,
41+ ) => {
42+ const { code } = req . body ;
4643
47- const { user, loginToken, refreshToken } = await authService . login ( code ) ;
44+ const { user, loginToken, refreshToken } = await authService . login ( code ) ;
4845
49- const workspaces = await userService . getWorkspaces ( Number ( user . id ) ) ;
46+ const cookieOptions : CookieOptions = {
47+ httpOnly : true ,
48+ sameSite : 'lax' ,
49+ maxAge : 1000 * 60 * 60 * 24 ,
50+ signed : true ,
51+ } ;
52+ res . cookie ( 'accessToken' , loginToken , cookieOptions ) ;
53+ res . cookie ( 'refreshToken' , refreshToken , cookieOptions ) ;
5054
51- const cookieOptions : CookieOptions = {
52- httpOnly : true ,
53- sameSite : 'lax' ,
54- maxAge : 1000 * 60 * 60 * 24 ,
55- signed : true ,
56- } ;
57- res . cookie ( 'accessToken' , loginToken , cookieOptions ) ;
58- res . cookie ( 'refreshToken' , refreshToken , cookieOptions ) ;
59-
60- res . status ( CREATED ) . send ( { user, workspaces } ) ;
61- } ) ,
55+ res . status ( CREATED ) . send ( { user } ) ;
56+ } ,
57+ ) ,
6258) ;
6359
6460router . delete (
0 commit comments