From 059c519f97689ca9021d07173e2f17ee87e4b998 Mon Sep 17 00:00:00 2001 From: Sophie Date: Tue, 23 Apr 2024 17:07:49 -0700 Subject: [PATCH] Move server URI to constant --- app/src/constants.ts | 1 + app/src/features/toolbar/hooks/useGithubAuth.ts | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 app/src/constants.ts diff --git a/app/src/constants.ts b/app/src/constants.ts new file mode 100644 index 0000000..9fc5846 --- /dev/null +++ b/app/src/constants.ts @@ -0,0 +1 @@ +export const SERVER_URI = process.env.REACT_APP_SERVER_URI ?? "http://localhost:8080" \ No newline at end of file diff --git a/app/src/features/toolbar/hooks/useGithubAuth.ts b/app/src/features/toolbar/hooks/useGithubAuth.ts index f07b189..50a7550 100644 --- a/app/src/features/toolbar/hooks/useGithubAuth.ts +++ b/app/src/features/toolbar/hooks/useGithubAuth.ts @@ -1,6 +1,7 @@ import { useCallback, useEffect, useState } from 'react'; import { useSearchParams } from 'react-router-dom'; import { useLocalSession } from '../../../utils/localStorage'; +import { SERVER_URI } from '../../../constants'; interface AuthenticatedUser { fullName: string; @@ -57,7 +58,7 @@ export function useGithubAuth(): [AuthenticatedUser | null, () => void] { const params = { code: githubCode, }; - const request = new Request('http://localhost:8080/login', { + const request = new Request(`${SERVER_URI}/login`, { method: 'POST', body: JSON.stringify(params), }); @@ -96,12 +97,9 @@ export function useGithubAuth(): [AuthenticatedUser | null, () => void] { return; } - const request = new Request( - `http://localhost:8080/session?id=${sessionId}`, - { - method: 'GET', - } - ); + const request = new Request(`${SERVER_URI}/session?id=${sessionId}`, { + method: 'GET', + }); fetch(request) .then((response) => { if (response.status < 400) {