From 35546c0c6d263c00a6fcb9db870610060c08cb60 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Tue, 26 Apr 2022 14:04:35 -0700 Subject: [PATCH] Added user registration call --- web/services/UserService.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 web/services/UserService.ts diff --git a/web/services/UserService.ts b/web/services/UserService.ts new file mode 100644 index 000000000..66bc7bdc1 --- /dev/null +++ b/web/services/UserService.ts @@ -0,0 +1,29 @@ +const URL_CHAT_REGISTRATION = `http://localhost:8080/api/chat/register`; + +interface UserRegistrationResponse { + id: string; + accessToken: string; + displayName: string; +} + +class UserService { + registerUser(username: string): Promise { + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + 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; + } +} \ No newline at end of file