@@ -37,9 +37,6 @@ exports.AuthService = void 0;
37
37
const common_1 = require ( "@nestjs/common" ) ;
38
38
const aws_sdk_1 = __importDefault ( require ( "aws-sdk" ) ) ;
39
39
const crypto = __importStar ( require ( "crypto" ) ) ;
40
- aws_sdk_1 . default . config . update ( {
41
- region : process . env . AWS_REGION ,
42
- } ) ;
43
40
let AuthService = AuthService_1 = class AuthService {
44
41
constructor ( ) {
45
42
this . logger = new common_1 . Logger ( AuthService_1 . name ) ;
@@ -187,14 +184,28 @@ let AuthService = AuthService_1 = class AuthService {
187
184
. promise ( ) ;
188
185
user = newUser ;
189
186
}
190
- return { access_token : idToken , user } ;
187
+ return { access_token : idToken , user, message : "Login Successful!" } ;
191
188
}
192
189
catch ( error ) {
193
- if ( error instanceof Error ) {
190
+ /* Login Failures */
191
+ const cognitoError = error ;
192
+ if ( cognitoError . code ) {
193
+ switch ( cognitoError . code ) {
194
+ case 'NotAuthorizedException' :
195
+ this . logger . warn ( `Login failed: ${ cognitoError . message } ` ) ;
196
+ throw new common_1 . UnauthorizedException ( 'Incorrect username or password.' ) ;
197
+ default :
198
+ this . logger . error ( `Login failed: ${ cognitoError . message } ` , cognitoError . stack ) ;
199
+ throw new common_1 . InternalServerErrorException ( 'An error occurred during login.' ) ;
200
+ }
201
+ }
202
+ else if ( error instanceof Error ) {
203
+ // Handle non-AWS errors
194
204
this . logger . error ( 'Login failed' , error . stack ) ;
195
- throw new Error ( error . message || 'Login failed' ) ;
205
+ throw new common_1 . InternalServerErrorException ( error . message || 'Login failed. ' ) ;
196
206
}
197
- throw new Error ( 'An unknown error occurred during login' ) ;
207
+ // Handle unknown errors
208
+ throw new common_1 . InternalServerErrorException ( 'An unknown error occurred during login.' ) ;
198
209
}
199
210
}
200
211
async setNewPassword ( newPassword , session , username , email ) {
0 commit comments