# Logout Icon

* This icon will navigate us to the login page.

<figure><img src="https://3585249674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9mSCXmgzkm8z0iToQdRK%2Fuploads%2FLIcvrUs5DRUAazHacubw%2FScreenshot%202024-01-03%20at%203.03.40%20PM.png?alt=media&#x26;token=c29c26b8-0318-4ebb-ae93-ee33c73b46aa" alt=""><figcaption><p>Logout Icon</p></figcaption></figure>

Upon selecting the logout option, the system redirects users to the login page and clears the local storage as a security measure.

<figure><img src="https://3585249674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9mSCXmgzkm8z0iToQdRK%2Fuploads%2F1Nk3VNeemFOcjg11NgAa%2FScreenshot%202024-01-03%20at%203.05.31%20PM.png?alt=media&#x26;token=ea0e805e-6cb3-4936-8ef5-e8862c989856" alt=""><figcaption><p>Login Page</p></figcaption></figure>

#### Logout Code Snippet

```
 logout(){
   localStorage.clear();
   this.router.navigateByUrl('/auth/login')
  }
```

#### Code Description

The logout function, when invoked by a user, is responsible for terminating the user's session. The two main actions performed by this function are:

**Clearing Local Storage**

* The line localStorage.clear(); ensures that any data stored in the web browser's localStorage, which could include information related to the user's session or authentication such as tokens or user preferences, is removed.

**Navigating to the Login Page**

* The subsequent line this.router.navigateByUrl('/auth/login'); utilizes a router service to direct the user to the '/auth/login' route. This navigation effectively redirects the user to the login page, facilitating a seamless transition after the logout process.
