@@ -34,18 +34,16 @@ const cookieOptions: CookieOptions = {
3434/* Returns access token and user info in response body and sets refreshToken as an httpOnly cookie */
3535authRouter . post ( "/login" , loginRequestValidator , async ( req , res ) => {
3636 try {
37- const authDTO = req . body . idToken
38- ? // OAuth
39- await authService . generateTokenOAuth ( req . body . idToken )
40- : await authService . generateToken ( req . body . email , req . body . password ) ;
37+ const authDTO = req . body . idToken ;
38+ await authService . generateToken ( req . body . email , req . body . password ) ;
4139
4240 const { refreshToken, ...rest } = authDTO ;
4341
4442 res
4543 . cookie ( "refreshToken" , refreshToken , cookieOptions )
4644 . status ( 200 )
4745 . json ( rest ) ;
48- } catch ( error : unknown ) {
46+ } catch ( error ) {
4947 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
5048 }
5149} ) ;
@@ -57,29 +55,22 @@ authRouter.post(
5755 async ( req , res ) => {
5856 try {
5957 if ( isAuthorizedByEmail ( req . body . email ) ) {
60- const user = await userService . getUserByEmail ( req . body . email ) ;
58+ const userDTO = await userService . getUserByEmail ( req . body . email ) ;
59+ const rest = { ...{ accessToken : req . body . accessToken } , ...userDTO } ;
6160
62- const activatedUser = user ;
63- activatedUser . status = UserStatus . ACTIVE ;
64- await userService . updateUserById ( user . id , activatedUser ) ;
65-
66- const rest = {
67- ...{ accessToken : req . body . accessToken } ,
68- ...activatedUser ,
69- } ;
7061 res
7162 . cookie ( "refreshToken" , req . body . refreshToken , cookieOptions )
7263 . status ( 200 )
7364 . json ( rest ) ;
7465 }
75- } catch ( error : unknown ) {
66+ } catch ( error ) {
7667 if ( error instanceof NotFoundError ) {
7768 res . status ( 404 ) . send ( getErrorMessage ( error ) ) ;
7869 } else {
7970 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
8071 }
8172 }
82- } ,
73+ }
8374) ;
8475
8576/* Returns access token in response body and sets refreshToken as an httpOnly cookie */
@@ -91,7 +82,7 @@ authRouter.post("/refresh", async (req, res) => {
9182 . cookie ( "refreshToken" , token . refreshToken , cookieOptions )
9283 . status ( 200 )
9384 . json ( { accessToken : token . accessToken } ) ;
94- } catch ( error : unknown ) {
85+ } catch ( error ) {
9586 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
9687 }
9788} ) ;
@@ -104,10 +95,10 @@ authRouter.post(
10495 try {
10596 await authService . revokeTokens ( req . params . userId ) ;
10697 res . status ( 204 ) . send ( ) ;
107- } catch ( error : unknown ) {
98+ } catch ( error ) {
10899 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
109100 }
110- } ,
101+ }
111102) ;
112103
113104/* Emails a password reset link to the user with the specified email */
@@ -118,10 +109,10 @@ authRouter.post(
118109 try {
119110 await authService . resetPassword ( req . params . email ) ;
120111 res . status ( 204 ) . send ( ) ;
121- } catch ( error : unknown ) {
112+ } catch ( error ) {
122113 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
123114 }
124- } ,
115+ }
125116) ;
126117
127118// updates user password and updates status
@@ -132,7 +123,7 @@ authRouter.post(
132123 try {
133124 const responseSuccess = await authService . setPassword (
134125 req . params . email ,
135- req . body . newPassword ,
126+ req . body . newPassword
136127 ) ;
137128 if ( responseSuccess . success ) {
138129 const user = await userService . getUserByEmail ( req . params . email ) ;
@@ -149,15 +140,15 @@ authRouter.post(
149140 } catch ( error ) {
150141 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
151142 }
152- } ,
143+ }
153144) ;
154145
155146/* Invite a user */
156147authRouter . post ( "/invite-user" , inviteUserDtoValidator , async ( req , res ) => {
157148 try {
158149 if (
159150 ! isAuthorizedByRole (
160- new Set ( [ Role . ADMINISTRATOR , Role . ANIMAL_BEHAVIOURIST ] ) ,
151+ new Set ( [ Role . ADMINISTRATOR , Role . ANIMAL_BEHAVIOURIST ] )
161152 )
162153 ) {
163154 res
@@ -184,7 +175,7 @@ authRouter.post("/invite-user", inviteUserDtoValidator, async (req, res) => {
184175 await userService . updateUserById ( user . id , invitedUser ) ;
185176
186177 res . status ( 204 ) . send ( ) ;
187- } catch ( error : unknown ) {
178+ } catch ( error ) {
188179 if ( error instanceof NotFoundError ) {
189180 res . status ( 404 ) . send ( getErrorMessage ( error ) ) ;
190181 } else {
0 commit comments