im trying to put this in my rest API, but i keep getting the TypeError.
import { Component, OnInit, Inject, Injectable } from '@angular/core';
import { AuthService } from "../core/auth.service";
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import * as firebase from 'firebase/app'; //Firebase SDK
@Injectable()
export class LoginService implements OnInit {
constructor(public auth: AuthService, private http: HttpClient) {
}
ngOnInit() {
}
lastLogin() {
firebase.auth().currentUser.getIdToken(true).then(function(idToken) {
// Send token to your backend via HTTPS
//console.log(idToken);
const req = this.http.put('https://dev-api.byrd.news/v1/login', {
user_token: idToken
})
.subscribe(
res => {
console.log(res);
},
err => {
console.log("error skete");
}
);
});
}
}
I call the function just for logging the lastLogin of a user, which is date and if it were a succes. Doing it through firebase, and i should receive an idToken according to the docs: https://firebase.google.com/docs/auth/admin/verify-id-tokens
What am i doing wrong?