0
I created an Interface to save user session information to use with an observable, idea and set when the user logs in and the other pages, and a service for HTTP requests will do the get of this Interface. The service for requesting Undefined after getting a get on the interface.
export interface ICredential {
IsLogged?: boolean;
XAccessToken?: string;
UserId?: string;
}
Page with login form
export class HomePage {
_ICredential: ICredential;
.....
GoogleSingIn(): void {
this._SocialAuthService.signIn(GoogleLoginProvider.PROVIDER_ID).then(
Data => {
....
this._ICredential = {
XAccessToken: this.XAccessToken,
UserId: this.UserId,
IsLogged: true,
}
})
})
}
In service Session I created the observable
Session(): Observable<ICredential> {
return new Observable<ICredential>(observer => {
observer.next(this._ICredential);
});
}
in the service with HTTP requests, I send a console.log and return Undefined
this._SessionService.Session().subscribe(
data => {
console.log(data.XAccessToken);
this.XAccessToken = data.XAccessToken },
error => alert(JSON.stringify(error))
)
The interface itself doesn’t have much to do with your problem, when you sign up for Session() Subscription is returning something ? You are making this application before or after you have called the method
GoogleSingIn
and how much such a method should be called? ... The interface simply serves to say what format your data has, whether or not you are receiving something has nothing to do with the interface– Leo Letto
Session is returning Undefined. I log in with Googlesigin and on the next page I try to recover data from the Interface. So my interpretation was wrong about the interface storing the data?
– RRV
Exactly, interfaces do not store any data except the format that the data that implement the interface should have, let me see if I understood the problem well: On page A you log in and redirect the user to page B where you call the method
Session()
and hopes to get the data you’ve stored before, that’s it?– Leo Letto
That’s right. Just as the next pages will use data that would be from Icredential to validate the session.
– RRV
This way it will never work, you set your
_ICredential
in the classHomePage
which I imagine to be its component, while its methodSession
is in the service_SessionService
which has never had any variable startup, create a single service or use what you already have in the case_SessionService
to authenticate and save the values you need, this way you do not lose this data when you browse between pages.– Leo Letto
I get it. Icredential is inside an Interface folder and I really use the Homepage as a home / login, so I will create inside this page the observable to return this information. The idea of _Sessionservice is to return session data
– RRV
Within the home I created a call to the service login and within this I created Behaviorsubject with the information I need during the user’s session. Posting here the final solution for people with little knowledge, as I rs.
– RRV