@annalib/anna-cognito-lib 2.2.8 → 2.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/components/forgot-password/forgot-password.component.mjs +2 -1
- package/esm2020/lib/services/auth.service.mjs +20 -12
- package/fesm2015/annalib-anna-cognito-lib.mjs +21 -12
- package/fesm2015/annalib-anna-cognito-lib.mjs.map +1 -1
- package/fesm2020/annalib-anna-cognito-lib.mjs +21 -12
- package/fesm2020/annalib-anna-cognito-lib.mjs.map +1 -1
- package/lib/services/auth.service.d.ts +2 -0
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { Validators, FormBuilder, FormsModule, ReactiveFormsModule } from '@angu
|
|
|
5
5
|
import * as i3$1 from '@angular/common/http';
|
|
6
6
|
import * as i3 from '@angular/router';
|
|
7
7
|
import { RouterModule } from '@angular/router';
|
|
8
|
-
import {
|
|
8
|
+
import { fetchAuthSession, signIn, confirmSignIn, getCurrentUser, resetPassword, confirmResetPassword, signOut } from 'aws-amplify/auth';
|
|
9
9
|
import * as i4 from 'ngx-toastr';
|
|
10
10
|
import * as i4$1 from '@angular/common';
|
|
11
11
|
import { CommonModule, NgOptimizedImage } from '@angular/common';
|
|
@@ -115,7 +115,7 @@ class AnnaLibAuthService {
|
|
|
115
115
|
ngOnInit() { }
|
|
116
116
|
async isUserLoggedIn() {
|
|
117
117
|
try {
|
|
118
|
-
await getCurrentUser();
|
|
118
|
+
// await getCurrentUser();
|
|
119
119
|
return new Promise(async (resolve, reject) => {
|
|
120
120
|
const session = await fetchAuthSession();
|
|
121
121
|
if (session?.tokens) {
|
|
@@ -140,7 +140,7 @@ class AnnaLibAuthService {
|
|
|
140
140
|
sessionTimeout() {
|
|
141
141
|
localStorage.clear();
|
|
142
142
|
clearInterval(this.accessTokenTimerId);
|
|
143
|
-
this.router.navigate([LoginConstant.loginPageUrl]);
|
|
143
|
+
this.router.navigate([this.defaultLoginPageUrl ? this.defaultLoginPageUrl : LoginConstant.loginPageUrl]);
|
|
144
144
|
}
|
|
145
145
|
computeTokenExpiration(idToken) {
|
|
146
146
|
let currentTime = Math.floor(Date.now() / 1000);
|
|
@@ -154,11 +154,7 @@ class AnnaLibAuthService {
|
|
|
154
154
|
switch (nextStep?.signInStep) {
|
|
155
155
|
case "DONE":
|
|
156
156
|
let session = await fetchAuthSession();
|
|
157
|
-
|
|
158
|
-
this.accessToken = session.tokens.accessToken.toString();
|
|
159
|
-
localStorage.setItem("accessTokenExpiration", newExpTime.toString());
|
|
160
|
-
this.refreshAccessToken();
|
|
161
|
-
this.loginErrorMessage = null;
|
|
157
|
+
this.onLoginOrSetNewPassword(session);
|
|
162
158
|
await this.consumingProjectAuthService.onSuccessfulAuthenticatingUser(false);
|
|
163
159
|
this.getAllCognitoTokenAndGroups(session.tokens);
|
|
164
160
|
break;
|
|
@@ -186,6 +182,14 @@ class AnnaLibAuthService {
|
|
|
186
182
|
}
|
|
187
183
|
}
|
|
188
184
|
}
|
|
185
|
+
onLoginOrSetNewPassword(session) {
|
|
186
|
+
let newExpTime = this.computeTokenExpiration(session.tokens.idToken);
|
|
187
|
+
this.accessToken = session.tokens.accessToken.toString();
|
|
188
|
+
this.IdToken = session.tokens.idToken.toString();
|
|
189
|
+
localStorage.setItem("accessTokenExpiration", newExpTime.toString());
|
|
190
|
+
this.refreshAccessToken();
|
|
191
|
+
this.loginErrorMessage = null;
|
|
192
|
+
}
|
|
189
193
|
async getAllCognitoTokenAndGroups(token) {
|
|
190
194
|
this.accessToken = token.accessToken.toString();
|
|
191
195
|
this.IdToken = token.idToken;
|
|
@@ -241,6 +245,8 @@ class AnnaLibAuthService {
|
|
|
241
245
|
const data = await confirmSignIn(inputParam);
|
|
242
246
|
const { username } = await getCurrentUser();
|
|
243
247
|
console.log(data);
|
|
248
|
+
let session = await fetchAuthSession();
|
|
249
|
+
this.onLoginOrSetNewPassword(session);
|
|
244
250
|
this.consumingProjectAuthService.onPasswordUpdate(username);
|
|
245
251
|
this.router.navigate([LoginConstant.loginPageUrl]);
|
|
246
252
|
this.consumingProjectAuthService.newPasswordSetThenUpdateToBackend(username);
|
|
@@ -266,16 +272,18 @@ class AnnaLibAuthService {
|
|
|
266
272
|
}
|
|
267
273
|
}
|
|
268
274
|
async verifyCode(confirmationCode, newPassword) {
|
|
269
|
-
const { username } = await getCurrentUser();
|
|
270
275
|
try {
|
|
271
|
-
|
|
272
|
-
this.
|
|
273
|
-
this.
|
|
276
|
+
// const { username } = await getCurrentUser();
|
|
277
|
+
confirmResetPassword({ username: this.userName, newPassword: newPassword, confirmationCode: confirmationCode });
|
|
278
|
+
this.consumingProjectAuthService.onPasswordUpdate(this.userName);
|
|
279
|
+
this.expiryAllExistingCurrentSession(this.userName, newPassword);
|
|
274
280
|
}
|
|
275
281
|
catch (err) {
|
|
276
282
|
console.log(err);
|
|
277
283
|
this.noOfAttempts = this.noOfAttempts + 1;
|
|
278
284
|
this.verifyAndSetNewPasswordErrorMessage = this.forgotPasswordError(err, this.noOfAttempts);
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
279
287
|
this.forgotPasswordAndGlobalSignoutLoader = false;
|
|
280
288
|
}
|
|
281
289
|
}
|
|
@@ -666,6 +674,7 @@ class ForgotPasswordComponent {
|
|
|
666
674
|
if (this.authService.userName) {
|
|
667
675
|
this.onUpdateForm();
|
|
668
676
|
}
|
|
677
|
+
this.authService.forgotPasswordAndGlobalSignoutLoader = false;
|
|
669
678
|
}
|
|
670
679
|
onIntialiseForm() {
|
|
671
680
|
this.verifyRegisteredEmail = this.fb.group({
|