I was put into a project where I have little experience with javascript/typescript/angular, so please excuse my ignorance. When a user logs in I have a post method api call that adds the user session and on a successful post it returns the sessionId which is a string. I need to know how to retrieve and store that string for later use in my application which will be used as a parameter for a couple different api calls. Here is my current service setup:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { catchError, retry } from 'rxjs/operators';
import { ConfigService } from './../config/config.service';
import { UserSession } from './user-session.interface';
import { ApiServiceBase } from '../shared/api-service-base'
@Injectable({
providedIn: 'root'
})
export class UserSessionService extends ApiServiceBase {
public userSession: UserSession;
private apiRoute: string = 'user-session';
constructor(http: HttpClient, configService: ConfigService) {
super(http, configService);
}
public async AddUserSession(userName: string): Promise<string> {
this.appSettings = (await this.configService.loadConfig().toPromise());
this.userSession = { userName: userName, application: this.application};
return this.http.post<string>(this.appSettings.apiSetting.apiAddress + this.apiRoute, this.userSession)
.pipe(
retry(1),
catchError(this.handleError)
)
.toPromise()
}
}
How can I retrieve and store the returned string?