Resolve "Auth providers should be ready on components init"

This commit is contained in:
Jovan Krunić
2022-05-13 09:05:33 +00:00
parent 28caaf1d21
commit b7ae2cf019
11 changed files with 77 additions and 96 deletions

View File

@@ -15,9 +15,16 @@ import {
AuthService,
AuthActionBuilder,
} from 'ionic-appauth';
import {ConfigProvider} from '../config/config.provider';
import {SCAuthorizationProvider} from '@openstapps/core';
import {getClientConfig, getEndpointsConfig} from './auth.provider.methods';
import {Injectable} from '@angular/core';
const TOKEN_RESPONSE_KEY = 'token_response';
@Injectable({
providedIn: 'root',
})
export class DefaultAuthService extends AuthService {
public localConfiguration: AuthorizationServiceConfiguration;
@@ -33,6 +40,7 @@ export class DefaultAuthService extends AuthService {
protected browser: Browser = new DefaultBrowser(),
protected storage: StorageBackend = new LocalStorageBackend(),
protected requestor: Requestor = new JQueryRequestor(),
private readonly configProvider: ConfigProvider,
) {
super(browser, storage, requestor);
}
@@ -44,6 +52,16 @@ export class DefaultAuthService extends AuthService {
return Promise.resolve(this.localConfiguration);
}
setupConfiguration() {
const authConfig = this.configProvider.getAnyValue('auth') as {
default: SCAuthorizationProvider;
};
this.authConfig = getClientConfig('default', authConfig);
this.localConfiguration = new AuthorizationServiceConfiguration(
getEndpointsConfig('default', authConfig),
);
}
public async signOut() {
await this.storage.removeItem(TOKEN_RESPONSE_KEY).catch(error => {
this.notifyActionListers(AuthActionBuilder.SignOutFailed(error));