@@ -43,7 +43,7 @@ authRouter.post("/login", loginRequestValidator, async (req, res) => {
4343 . cookie ( "refreshToken" , refreshToken , cookieOptions )
4444 . status ( 200 )
4545 . json ( rest ) ;
46- } catch ( error : unknown ) {
46+ } catch ( error ) {
4747 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
4848 }
4949} ) ;
@@ -55,22 +55,28 @@ authRouter.post(
5555 async ( req , res ) => {
5656 try {
5757 if ( isAuthorizedByEmail ( req . body . email ) ) {
58- const userDTO = await userService . getUserByEmail ( req . body . email ) ;
59- const rest = { ...{ accessToken : req . body . accessToken } , ...userDTO } ;
60-
58+ const user = await userService . getUserByEmail ( req . body . email ) ;
59+ const activatedUser = user ;
60+ activatedUser . status = UserStatus . ACTIVE ;
61+ await userService . updateUserById ( user . id , activatedUser ) ;
62+
63+ const rest = {
64+ ...{ accessToken : req . body . accessToken } ,
65+ ...activatedUser ,
66+ } ;
6167 res
6268 . cookie ( "refreshToken" , req . body . refreshToken , cookieOptions )
6369 . status ( 200 )
6470 . json ( rest ) ;
6571 }
66- } catch ( error : unknown ) {
72+ } catch ( error ) {
6773 if ( error instanceof NotFoundError ) {
6874 res . status ( 404 ) . send ( getErrorMessage ( error ) ) ;
6975 } else {
7076 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
7177 }
7278 }
73- } ,
79+ }
7480) ;
7581
7682/* Returns access token in response body and sets refreshToken as an httpOnly cookie */
@@ -82,7 +88,7 @@ authRouter.post("/refresh", async (req, res) => {
8288 . cookie ( "refreshToken" , token . refreshToken , cookieOptions )
8389 . status ( 200 )
8490 . json ( { accessToken : token . accessToken } ) ;
85- } catch ( error : unknown ) {
91+ } catch ( error ) {
8692 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
8793 }
8894} ) ;
@@ -95,10 +101,10 @@ authRouter.post(
95101 try {
96102 await authService . revokeTokens ( req . params . userId ) ;
97103 res . status ( 204 ) . send ( ) ;
98- } catch ( error : unknown ) {
104+ } catch ( error ) {
99105 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
100106 }
101- } ,
107+ }
102108) ;
103109
104110/* Emails a password reset link to the user with the specified email */
@@ -109,10 +115,10 @@ authRouter.post(
109115 try {
110116 await authService . resetPassword ( req . params . email ) ;
111117 res . status ( 204 ) . send ( ) ;
112- } catch ( error : unknown ) {
118+ } catch ( error ) {
113119 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
114120 }
115- } ,
121+ }
116122) ;
117123
118124// updates user password and updates status
@@ -123,7 +129,7 @@ authRouter.post(
123129 try {
124130 const responseSuccess = await authService . setPassword (
125131 req . params . email ,
126- req . body . newPassword ,
132+ req . body . newPassword
127133 ) ;
128134 if ( responseSuccess . success ) {
129135 const user = await userService . getUserByEmail ( req . params . email ) ;
@@ -137,18 +143,18 @@ authRouter.post(
137143 } else {
138144 res . status ( 400 ) . json ( responseSuccess ) ;
139145 }
140- } catch ( error : unknown ) {
146+ } catch ( error ) {
141147 res . status ( 500 ) . json ( { error : getErrorMessage ( error ) } ) ;
142148 }
143- } ,
149+ }
144150) ;
145151
146152/* Invite a user */
147153authRouter . post ( "/invite-user" , inviteUserDtoValidator , async ( req , res ) => {
148154 try {
149155 if (
150156 ! isAuthorizedByRole (
151- new Set ( [ Role . ADMINISTRATOR , Role . ANIMAL_BEHAVIOURIST ] ) ,
157+ new Set ( [ Role . ADMINISTRATOR , Role . ANIMAL_BEHAVIOURIST ] )
152158 )
153159 ) {
154160 res
@@ -175,7 +181,7 @@ authRouter.post("/invite-user", inviteUserDtoValidator, async (req, res) => {
175181 await userService . updateUserById ( user . id , invitedUser ) ;
176182
177183 res . status ( 204 ) . send ( ) ;
178- } catch ( error : unknown ) {
184+ } catch ( error ) {
179185 if ( error instanceof NotFoundError ) {
180186 res . status ( 404 ) . send ( getErrorMessage ( error ) ) ;
181187 } else {
0 commit comments