Skip to content

Instantly share code, notes, and snippets.

@tiagolpadua
Created March 18, 2021 22:26
Show Gist options
  • Save tiagolpadua/aeb8aff80b2fe93a2a61e4e76b14467d to your computer and use it in GitHub Desktop.
Save tiagolpadua/aeb8aff80b2fe93a2a61e4e76b14467d to your computer and use it in GitHub Desktop.
cmail\src\app\services\login.service.ts
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