refactor: adapting token storage to the API
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
import {Injectable} from "@angular/core";
|
||||
import ApiService, {AvailableVersion} from "@api/api.service";
|
||||
import {LoginRequest} from "@api/v1/loginRequest";
|
||||
import {TokenResponse} from "@api/v1/tokenResponse";
|
||||
import {catchError, of, tap} from "rxjs";
|
||||
import {catchError, of} from "rxjs";
|
||||
import {AuthRoles} from "@model/AuthRoles";
|
||||
import {AuthService, AvailableAuthenticationProvider} from "@service/auth.service";
|
||||
|
||||
@Injectable()
|
||||
export default class AuthApiService extends ApiService {
|
||||
@ -18,13 +16,16 @@ export default class AuthApiService extends ApiService {
|
||||
.setWithCredentials()
|
||||
.build;
|
||||
|
||||
return this.post<TokenResponse>(request)
|
||||
.pipe(
|
||||
tap(response => {
|
||||
AuthService.setToken(response, AvailableAuthenticationProvider.Bearer, this.combinedUrl(this.createRequestBuilder().setEndpoint('ReLogin').build));
|
||||
this.tokenRefreshService.setRefreshTokenExpireMs(response.expiresIn);
|
||||
})
|
||||
);
|
||||
return this.post<AuthRoles>(request);
|
||||
}
|
||||
|
||||
public reLogin(){
|
||||
let request = this.createRequestBuilder()
|
||||
.setEndpoint('ReLogin')
|
||||
.setWithCredentials()
|
||||
.build;
|
||||
|
||||
return this.get<AuthRoles>(request);
|
||||
}
|
||||
|
||||
public logout() {
|
||||
@ -33,13 +34,7 @@ export default class AuthApiService extends ApiService {
|
||||
.setEndpoint('Logout')
|
||||
.build;
|
||||
|
||||
return this.addAuth(request)
|
||||
.get(request)
|
||||
.pipe(
|
||||
tap(_ => {
|
||||
localStorage.removeItem(ApiService.tokenKey);
|
||||
})
|
||||
);
|
||||
return this.addAuth(request).get(request);
|
||||
}
|
||||
|
||||
public getRole(isSilence: boolean = true) {
|
||||
|
Reference in New Issue
Block a user