Created
March 18, 2021 22:26
-
-
Save tiagolpadua/aeb8aff80b2fe93a2a61e4e76b14467d to your computer and use it in GitHub Desktop.
cmail\src\app\services\login.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { HttpClient, HttpHeaders } from '@angular/common/http'; | |
| import { Injectable } from '@angular/core'; | |
| import { tap } from 'rxjs/operators'; | |
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class LoginService { | |
| api = 'http://localhost:3200/login' | |
| constructor(private http: HttpClient) { } | |
| logar(dadosLogin) { | |
| return this.http.post(this.api, dadosLogin) | |
| .pipe( | |
| tap((response: any) => localStorage.setItem('cmail-token', response.token)) | |
| ); | |
| } | |
| // Novo código aqui | |
| validaToken() { | |
| const headers = new HttpHeaders({ | |
| 'Content-Type': 'application/json', | |
| 'Authorization': localStorage.getItem('cmail-token') | |
| }); | |
| return this.http | |
| .head( | |
| 'http://localhost:3200/validate' | |
| , { | |
| headers | |
| , observe: 'response' | |
| } | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment