diff --git a/src/app/auth/auth-config.module.ts b/src/app/auth/auth-config.module.ts index 2a6640b..cdafdce 100644 --- a/src/app/auth/auth-config.module.ts +++ b/src/app/auth/auth-config.module.ts @@ -20,7 +20,7 @@ export function configureAuth(oidcConfigService: OidcConfigService): () => Promi tokenRefreshInSeconds: 20, ignoreNonceAfterRefresh: true, // El refresh token está fallando si no se ignora el Nonce secureRoutes: [TRAVEL_API_URL, USER_API_URL], - // storage: localStorage, + storage: localStorage, logLevel: LogLevel.Warn }); } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 38372af..b7e4cd2 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -53,15 +53,16 @@ export class AuthService { this.userSubject.next(User.fromClaims(claims)); }); - if ((sessionStorage.getItem('chatLoginInProcess') === 'true') || chatLoginToken) { - sessionStorage.removeItem('chatLoginInProcess'); + return this.oidcSecurityService.checkAuth().toPromise().then(async (auth) => { + console.log('AUTH INITIALIZED result=', auth); + + if (auth) { + if (sessionStorage.getItem('chatLoginInProcess') === 'true') { + sessionStorage.removeItem('chatLoginInProcess'); - return this.oidcSecurityService.checkAuth().toPromise().then((auth) => { - console.log('AUTH INITIALIZED result=', auth); - if (auth) { if (chatLoginToken) { console.log('chatLoginToken=' + chatLoginToken); - this.chatService.login(chatLoginToken); + await this.chatService.login(chatLoginToken); } else { console.error('CHAT LOGIN TOKEN NOT RECEIVED'); @@ -72,23 +73,15 @@ export class AuthService { return AuthState.Logged; } - - return AuthState.NotLogged; - }); - } - else { - return this.oidcSecurityService.checkAuthIncludingServer().toPromise().then((auth) => { - console.log('AUTH INITIALIZED result=', auth); - - if (auth) { + else { console.log('GO TO SSO LOGIN'); sessionStorage.setItem('chatLoginInProcess', 'true'); this.chatService.goToSsoLogin(); return AuthState.ChatLoggingInProcess; } + } - return AuthState.NotLogged; - }); - } + return AuthState.NotLogged; + }); } } diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index 5e2ddd8..5a2db55 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -14,27 +14,24 @@ export class ChatService { window.location.href = 'http://synapse:8008/_matrix/client/r0/login/sso/redirect?redirectUrl=http://localhost:4200/'; } - login(loginToken: string): Promise { - return this.http.post( + async login(loginToken: string): Promise { + const res = await this.http.post( 'http://synapse:8008/_matrix/client/r0/login', { initial_device_display_name: 'Okupa mi coche', token: loginToken, type: 'm.login.token' } - ).toPromise().then(res => { - console.log('LOGGED TO CHAT'); - console.log(res); - - const client = matrix.createClient({ - baseUrl: "http://localhost:8008", - accessToken: res['access_token'], - userId: res['user_id'] - }); - - client.publicRooms(function (err, data) { - console.log("Public Rooms: %s", JSON.stringify(data)); - }); + ).toPromise(); + console.log('LOGGED TO CHAT'); + console.log(res); + const client = matrix.createClient({ + baseUrl: 'http://localhost:8008', + accessToken: res['access_token'], + userId: res['user_id'] + }); + client.publicRooms((err: any, data: any) => { + console.log('Public Rooms: %s', JSON.stringify(data)); }); } }