Open Closed

Clearing Session Storage on logout in Angular #5841


User avatar
0
SamirBoutazzout created

Hey guys, i'm trying to fix an issue I have on the frontend. I would like to clear the sessionStorage from an item I set during the session of a user. I've been looking around on the documentation and google but I couldn't find an answer. Is there a hook or a service exposed in Angular where I can clear the session on logout? Basically, I want to clear the sessionStorage when the user logs out. The issue i'm having is when I logout with an account, and log in with another, the items from the previous session are persisted and this is causing an issue.

Thank you

  • ABP Framework version: v6.0.2 Commercial
  • UI Type: Angular
  • Database System: EF Core (PostgreSQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

2 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Member

    Hello SamirBoutazzout, Can you please try this. Try to add this code in app.component.ts file.

    import { AuthService } from '@abp/ng.core';
    import { Router } from '@angular/router';
    import { OAuthService } from 'angular-oauth2-oidc';
    import { filter, tap } from 'rxjs';
    constructor(private oAuthService: OAuthService , private router: Router, private authService: AuthService) {
    this.oAuthService.events
        .pipe(filter(event => event?.type === 'logout'),
          tap(() => {
            sessionStorage.clear();
          })).subscribe();
      }
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    SamirBoutazzout created

    Hi Anjali_Musmade,

    Thank you very much. That worked like a charm. I appreciate it.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.