Skip to content

Commit c5704d2

Browse files
committed
refact: Read from dotenv
1 parent 7a6dc3e commit c5704d2

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

src/domain/AuthState.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { api } from 'api';
22
import React from 'react';
33
import { pipe, tagged, task, taskEither } from '@code-expert/prelude';
44
import { getAccess } from '@/api/oauth/getAccess';
5+
import { config } from '@/config';
56
import useTimeout from '@/ui/hooks/useTimeout';
67
import { pkceChallenge } from '@/utils/crypto';
78
import { ClientId } from './ClientId';
@@ -21,7 +22,7 @@ const startingAuthorization = (
2122
): Extract<AuthState, { _tag: 'startingAuthorization' }> => {
2223
const { code_verifier, code_challenge } = pkceChallenge();
2324

24-
const redirectLink = `${api.CXUrl}/app/authorize?clientId=${clientId}&code_challenge=${code_challenge}`;
25+
const redirectLink = `${config.CX_WEB_URL}/app/authorize?clientId=${clientId}&code_challenge=${code_challenge}`;
2526

2627
return authState.startingAuthorization({ code_verifier, redirectLink });
2728
};
@@ -84,7 +85,9 @@ export const useAuthState = (
8485

8586
if (authState.is.waitingForAuthorization(state)) {
8687
if (sse.current == null) {
87-
sse.current = new EventSource(`${api.APIUrl}/app/oauth/listenForAuthToken/${clientId}`);
88+
sse.current = new EventSource(
89+
`${config.CX_API_URL}/app/oauth/listenForAuthToken/${clientId}`,
90+
);
8891
}
8992

9093
sse.current?.addEventListener('authToken', onAuthToken, { once: true });

src/domain/ProjectAccess.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { api } from 'api';
21
import React from 'react';
32
import { either, pipe, task } from '@code-expert/prelude';
3+
import { config } from '@/config';
44
import { createToken } from './createAPIRequest';
55

66
const cleanUpEventListener = (
@@ -32,7 +32,9 @@ export const useProjectAccess = (onProjectAccess: (projectId: string) => void) =
3232
createToken({}),
3333
task.map((token) => {
3434
if (either.isRight(token)) {
35-
sse.current = new EventSource(`${api.APIUrl}/app/projectAccess?token=${token.right}`);
35+
sse.current = new EventSource(
36+
`${config.CX_API_URL}/app/projectAccess?token=${token.right}`,
37+
);
3638
sse.current.addEventListener('projectAccess', onProjectAccessI);
3739
sse.current.addEventListener('error', onError);
3840
}

src/domain/createAPIRequest.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Body, Response, ResponseType, fetch } from '@tauri-apps/api/http';
22
import { api } from 'api';
33
import { either, flow, iots, pipe, taskEither } from '@code-expert/prelude';
4+
import { config } from '@/config';
45
import { ClientId } from './ClientId';
56
import {
67
EntityNotFoundException,
@@ -23,7 +24,7 @@ function sendApiRequest(path: string, method: 'GET' | 'POST', responseType: Resp
2324
return (token: string) =>
2425
taskEither.tryCatch(
2526
() =>
26-
fetch(new URL(path, api.APIUrl).href, {
27+
fetch(new URL(path, config.CX_API_URL).href, {
2728
method,
2829
headers: {
2930
Authorization: `Bearer ${token}`,
@@ -38,7 +39,7 @@ function sendApiRequestPayload(path: string, method: 'GET' | 'POST') {
3839
return (payload: Record<string, unknown>) =>
3940
taskEither.tryCatch(
4041
() =>
41-
fetch(new URL(path, api.APIUrl).href, {
42+
fetch(new URL(path, config.CX_API_URL).href, {
4243
method,
4344
body: Body.json(payload),
4445
responseType: ResponseType.JSON,

src/startup/getClientToken.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { api } from 'api';
22
import { iots, pipe, taskEither } from '@code-expert/prelude';
3+
import { config } from '@/config';
34
import { ClientId } from '@/domain/ClientId';
45
import { createAPIRequest } from '@/domain/createAPIRequest';
56

@@ -11,7 +12,7 @@ export const getClientToken = pipe(
1112
taskEither.alt(() =>
1213
pipe(
1314
createAPIRequest({
14-
path: `${api.APIUrl}/app/clientId`,
15+
path: `${config.CX_API_URL}/app/clientId`,
1516
method: 'GET',
1617
payload: {},
1718
codec: iots.strict({ token: iots.string }),

src/startup/registerApp.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { invoke } from '@tauri-apps/api';
22
import { getName, getVersion } from '@tauri-apps/api/app';
33
import { api } from 'api';
44
import { constVoid, iots, pipe, taskEither } from '@code-expert/prelude';
5+
import { config } from '@/config';
56
import { createAPIRequest } from '@/domain/createAPIRequest';
67
import { getClientToken } from './getClientToken';
78

@@ -23,7 +24,7 @@ const registerApp = async () => {
2324

2425
return pipe(
2526
createAPIRequest({
26-
path: `${api.APIUrl}/app/register`,
27+
path: `${config.CX_API_URL}/app/register`,
2728
payload: requestBody,
2829
method: 'POST',
2930
codec: iots.strict({ clientId: iots.string }),

src/ui/pages/projects/hooks/useProjectEventUpdate.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { api } from 'api';
21
import React from 'react';
32
import { pipe, task, taskEither } from '@code-expert/prelude';
3+
import { config } from '@/config';
44
import { ClientId } from '@/domain/ClientId';
55
import { createTokenWithClientId } from '@/domain/createAPIRequest';
66

@@ -15,7 +15,9 @@ export const useProjectEventUpdate = (onProjectAdded: () => void, clientId: Clie
1515
createTokenWithClientId({})(clientId),
1616
taskEither.map((token) => {
1717
if (sse.current == null) {
18-
sse.current = new EventSource(`${api.APIUrl}/app/projectAccess?token=${token}`);
18+
sse.current = new EventSource(
19+
`${config.CX_API_URL}/app/projectAccess?token=${token}`,
20+
);
1921
sse.current.addEventListener('projectAccess', onProjectAdd);
2022
sse.current.addEventListener('error', onError);
2123
}

0 commit comments

Comments
 (0)