Handle centralized app state and registration + chat history
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ChatMessage } from '../interfaces/chat-message.model';
|
||||
import { getUnauthedData } from '../utils/apis';
|
||||
const ENDPOINT = `http://localhost:8080/api/chat`;
|
||||
const URL_CHAT_REGISTRATION = `http://localhost:8080/api/chat/register`;
|
||||
|
||||
@@ -10,9 +11,8 @@ interface UserRegistrationResponse {
|
||||
|
||||
class ChatService {
|
||||
public static async getChatHistory(accessToken: string): Promise<ChatMessage[]> {
|
||||
const response = await fetch(`${ENDPOINT}?accessToken=${accessToken}`);
|
||||
const status = await response.json();
|
||||
return status;
|
||||
const response = await getUnauthedData(`${ENDPOINT}?accessToken=${accessToken}`);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static async registerUser(username: string): Promise<UserRegistrationResponse> {
|
||||
@@ -24,15 +24,8 @@ class ChatService {
|
||||
body: JSON.stringify({ displayName: username }),
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(URL_CHAT_REGISTRATION, options);
|
||||
const result = await response.json();
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
const response = await getUnauthedData(URL_CHAT_REGISTRATION, options);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user