I have been assigned to a project involving javascript/typescript/angular, even though I have limited experience with these technologies. As a result, please bear with me as I may lack some knowledge in this area. In the scenario where a user logs in, there is a post method api call that assigns the user session and returns a sessionId as a string upon successful completion. My objective is to understand how to fetch and save this string for future use within my application, particularly as a parameter for different api calls. Below is my existing service configuration:
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()
}
}
Could you provide guidance on how to access and retain the returned string?