Skip to content

Commit

Permalink
DON-933: Remove async for deleting session cookie, add explicit overw…
Browse files Browse the repository at this point in the history
…rite
  • Loading branch information
bdsl committed Nov 28, 2023
1 parent 9992f18 commit 953b58d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,13 @@ export class DonationStartFormComponent implements AfterContentChecked, AfterCon
this.stepHeaderEventsSet = true;
}

reset = async () => {
reset = () => {
this.donor = undefined;
this.creditPenceToUse = 0;
this.stripePaymentMethodReady = false;
this.paymentReadinessTracker = new PaymentReadinessTracker(this.paymentGroup,);
this.donationForm.reset();
await this.identityService.clearJWT();
this.identityService.clearJWT();
this.idCaptcha.reset();
this.destroyStripeElements();

Expand Down
12 changes: 4 additions & 8 deletions src/app/identity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,13 @@ export class IdentityService {
).pipe(retry(2), delay(2_000));
}

/**
* We've seen logout not working in some cases, perhaps because use of navigate imediatly after deleting the cookie
* is making the cookie deletion un reliable. So await this function before navigating.
*/
async clearJWT() {
clearJWT() {
this.cookieService.delete(this.cookieName);

// delete didn't seem to work reliably, so also directly setting an empty cookie that expires in the past here:
this.cookieService.set(this.cookieName, '', new Date('1970-01-01'), '/')
this.storage.remove(this.storageKey);
this.loginStatusChanged.emit(false);

const point4Seconds = 4_00;
await new Promise(resolve => setTimeout(resolve, point4Seconds));
}

getIdAndJWT(): { id: string, jwt: string } | undefined {
Expand Down
4 changes: 2 additions & 2 deletions src/app/my-account/my-account.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export class MyAccountComponent implements OnDestroy, OnInit {
);
}

async logout() {
await this.identityService.clearJWT();
logout() {
this.identityService.clearJWT();
this.router.navigate(['']);
}

Expand Down

0 comments on commit 953b58d

Please sign in to comment.