Bug session expired resolved

This commit is contained in:
Eudes Inácio
2022-06-08 11:56:56 +01:00
parent f1e8cedc35
commit 73d0696ea6
15 changed files with 121 additions and 9 deletions
@@ -10,6 +10,7 @@ import { FileLoaderService } from 'src/app/services/file/file-loader.service';
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
import { environment } from 'src/environments/environment';
import { ThemeService } from 'src/app/services/theme.service'
import { HttpErrorResponse } from '@angular/common/http';
@Component({
selector: 'app-chat-options-features',
@@ -117,8 +118,12 @@ export class ChatOptionsFeaturesPage implements OnInit {
this.chatService.sendMessage(body).subscribe(res=> {
//
},(error) => {
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.chatService.sendMessage(body);
}
});
//
};
@@ -144,8 +149,12 @@ export class ChatOptionsFeaturesPage implements OnInit {
this.chatService.sendMessage(body).subscribe(res=> {
},(error) => {
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.chatService.sendMessage(body);
}
});
}
+7 -1
View File
@@ -1,4 +1,4 @@
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
import {
Component,
OnInit,
@@ -507,6 +507,12 @@ export class ChatPage implements OnInit {
//
}*/
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.getChatMembers();
}
});
}
@@ -1,3 +1,4 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams, PickerController } from '@ionic/angular';
import { ChatService } from 'src/app/services/chat.service';
@@ -36,6 +37,11 @@ export class EditGroupPage implements OnInit {
this.room = room['room'];
this.groupName = this.room.name.split('-').join(' ');
},(error: HttpErrorResponse) => {
if(error.status === 401) {
this.chatService.refreshtoken();
this.getRoomInfo()
}
});
}
@@ -1,4 +1,4 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';
import * as _ from 'lodash';
@@ -85,6 +85,12 @@ export class GroupContactsPage implements OnInit {
this.showLoader = false;
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.loadUsers();
}
});
}
@@ -31,6 +31,7 @@ import { MessageService } from 'src/app/services/chat/message.service';
import { File } from '@awesome-cordova-plugins/file/ngx';
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { SessionStore } from 'src/app/store/session.service';
import { HttpErrorResponse } from '@angular/common/http';
@Component({
selector: 'app-group-messages',
@@ -380,6 +381,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.allUsers = res['users'].filter(data => data.username != SessionStore.user.UserName);
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.getChatMembers();
}
});
}
@@ -1,4 +1,4 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service';
@@ -67,6 +67,12 @@ export class ContactsPage implements OnInit {
return 0;
});
this.showLoader = false;
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.loadUsers();
}
});
}
@@ -36,6 +36,7 @@ import { FileToBase64Service } from 'src/app/services/file/file-to-base64.servic
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { DomSanitizer } from '@angular/platform-browser';
import { SessionStore } from 'src/app/store/session.service';
import { HttpErrorResponse } from '@angular/common/http';
const IMAGE_DIR = 'stored-images';
@@ -519,6 +520,12 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.members = res['members'];
this.dmUsers = res['members'].filter(data => data.username != this.sessionStore.user.UserName)
this.showLoader = false;
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.getChatMembers();
}
});
}
+18
View File
@@ -350,4 +350,22 @@ export class ChatService {
}
refreshtoken(){
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
let options = {
headers: this.headers
};
return this.http.get(environment.apiURL+'UserAuthentication/RegenereChatToken',options).subscribe(async res => {
let data = {
status: res['status'],
data: {
userId: res['data'].userId,
authToken: res['data'].authToken }
}
SessionStore.user.ChatData = data
console.log(res)
console.log(SessionStore.user.ChatData)
});
}
}
@@ -1,3 +1,4 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ModalController, PickerController } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service';
@@ -41,6 +42,12 @@ export class EditGroupPage implements OnInit {
this.room = room['room'];
this.groupName = this.room.name.split('-').join(' ');
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.getRoomInfo();
}
});
}
@@ -1,4 +1,4 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';
import * as _ from 'lodash';
@@ -203,6 +203,12 @@ export class GroupContactsPage implements OnInit {
this.showLoader = false;
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.loadUsers();
}
});
}
@@ -34,6 +34,7 @@ import { AlertController } from '@ionic/angular';
import { File } from '@awesome-cordova-plugins/file/ngx';
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { SessionStore } from 'src/app/store/session.service';
import { HttpErrorResponse } from '@angular/common/http';
/*
@@ -366,6 +367,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.allUsers = res['users'].filter(data => data.username != SessionStore.user.UserName);
//
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.getChatMembers();
}
});
}
@@ -1,4 +1,4 @@
import { HttpHeaders } from '@angular/common/http';
import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { AuthService } from 'src/app/services/auth.service';
@@ -83,6 +83,12 @@ export class ContactsPage implements OnInit {
return 0;
});
this.showLoader = false;
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.loadUsers();
}
});
}
@@ -31,6 +31,7 @@ import { AlertController, Platform } from '@ionic/angular';
import { File } from '@awesome-cordova-plugins/file/ngx';
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { SessionStore } from 'src/app/store/session.service';
import { HttpErrorResponse } from '@angular/common/http';
const IMAGE_DIR = 'stored-images';
@@ -524,6 +525,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.members = res['members'];
this.dmUsers = res['members'].filter(data => data.username != this.sessionStore.user.UserName)
this.showLoader = false;
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.getChatMembers();
}
});
}
@@ -5,6 +5,7 @@ import { ToastService } from 'src/app/services/toast.service';
import { ThemeService } from 'src/app/services/theme.service'
import { SetRoomOwnerPage } from 'src/app/modals/set-room-owner/set-room-owner.page';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { HttpErrorResponse } from '@angular/common/http';
@Component({
@@ -168,6 +169,12 @@ export class ChatPopoverPage implements OnInit {
});
}
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.deleteGroup();
}
});
this.popoverController.dismiss('delete');
this.modalController.dismiss('delete');
@@ -1,3 +1,4 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams, PopoverController } from '@ionic/angular';
import { ChatService } from 'src/app/services/chat.service';
@@ -41,6 +42,12 @@ export class MessagesOptionsPage implements OnInit {
let body = { "roomId": this.roomId }
this.chatService.removeChatRoom(body).subscribe(res=>{
},(error: HttpErrorResponse) => {
if(error.status === 401){
this.chatService.refreshtoken()
this.closeChatRoom();
}
});
this.close();
}