Skip to content

Commit 050b758

Browse files
committed
changes requested in review
1 parent fb3d8af commit 050b758

4 files changed

Lines changed: 20 additions & 25 deletions

File tree

plugins/tagoio-integration/src/back/Request.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ async function createTCore(token: string, data: any) {
99
try {
1010
const region = (await pluginStorage.get("region")) || "us-e1";
1111
const response = await axios({
12+
//TODO: fix this import and check if works
1213
url: `${getConnectionURI.default.default(region).api}/tcore/instance`,
1314
method: "POST",
1415
headers: { token },
@@ -32,6 +33,7 @@ async function sendDataToTagoio(
3233
try {
3334
const region = (await pluginStorage.get("region")) || "us-e1";
3435
const response = await axios({
36+
//TODO: fix this import and check if works
3537
url: `${getConnectionURI.default.default(region).api}/tcore/sse/${connId}`,
3638
method: "POST",
3739
headers: { token },

plugins/tagoio-integration/src/back/Server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
startRealtimeCommunication,
1414
} from "./RealtimeConnection.ts";
1515
import { createTCore, sendDataToTagoio } from "./Request.ts";
16+
import { regionsDefinition } from "@tago-io/sdk/lib/regions.js";
1617

1718
let server: http.Server | null = null;
1819

@@ -86,6 +87,11 @@ async function routeStartTCore(req: Request, res: Response) {
8687
const osInfo = await helpers.getOSInfo();
8788
const profileToken = "p-".concat(req.headers.token as string);
8889
const region = req.headers.region as string;
90+
if (!regionsDefinition[region as keyof typeof regionsDefinition]) {
91+
res.sendStatus(400);
92+
return;
93+
}
94+
8995
await pluginStorage.set("region", region);
9096
const item = await pluginStorage.get("tcore").catch(() => null);
9197

plugins/tagoio-integration/src/front/Auth/Auth.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,7 @@ import InstanceName from "./InstanceName/InstanceName.tsx";
1010
import Otp from "./Otp/Otp.tsx";
1111
import OtpPicker from "./OtpPicker/OtpPicker.tsx";
1212
import Profiles from "./Profiles/Profiles.tsx";
13-
14-
// Region configuration
15-
const REGIONS = {
16-
"us-e1": {
17-
label: "United States East 1",
18-
apiUrl: "https://api.tago.io",
19-
},
20-
"eu-w1": {
21-
label: "Europe West 1",
22-
apiUrl: "https://api.eu-w1.tago.io",
23-
},
24-
};
13+
import { REGIONS } from "./regions.ts";
2514

2615
/**
2716
* Props.
@@ -63,7 +52,7 @@ function Auth(props: IAuthProps) {
6352
const { onSignIn, port } = props;
6453

6554
// Get the API URL based on selected region
66-
const API_URL = REGIONS[selectedRegion].apiUrl;
55+
const apiUrl = REGIONS[selectedRegion].apiUrl;
6756

6857
/**
6958
* Logs in.
@@ -82,7 +71,7 @@ function Auth(props: IAuthProps) {
8271

8372
// logs in and gets the account
8473
const result = await axios.post(
85-
`${API_URL}/account/login`,
74+
`${apiUrl}/account/login`,
8675
{
8776
email,
8877
password,
@@ -114,7 +103,7 @@ function Auth(props: IAuthProps) {
114103
setLoading(false);
115104
}
116105
},
117-
[email, password, loading, otpType, API_URL],
106+
[email, password, loading, otpType, apiUrl],
118107
);
119108

120109
/**
@@ -151,7 +140,7 @@ function Auth(props: IAuthProps) {
151140

152141
// uses the account to get a profile token
153142
// logs in and gets the account
154-
const tokenData = await axios.post(`${API_URL}/account/profile/token`, {
143+
const tokenData = await axios.post(`${apiUrl}/account/profile/token`, {
155144
email,
156145
password,
157146
otp_type: lastPinCode ? otpType : undefined,
@@ -170,7 +159,7 @@ function Auth(props: IAuthProps) {
170159
setLoading(false);
171160
}
172161
},
173-
[email, otpType, lastPinCode, password, API_URL],
162+
[email, otpType, lastPinCode, password, apiUrl],
174163
);
175164

176165
/**
@@ -205,14 +194,14 @@ function Auth(props: IAuthProps) {
205194
setContent("otp");
206195

207196
if (newType !== "authenticator") {
208-
await axios.post(`${API_URL}/account/login/otp`, {
197+
await axios.post(`${apiUrl}/account/login/otp`, {
209198
email,
210199
password,
211200
otp_type: newType,
212201
});
213202
}
214203
},
215-
[email, password, API_URL],
204+
[email, password, apiUrl],
216205
);
217206

218207
/**
@@ -246,7 +235,6 @@ function Auth(props: IAuthProps) {
246235
password={password}
247236
selectedRegion={selectedRegion}
248237
onChangeRegion={setSelectedRegion}
249-
regions={REGIONS}
250238
/>
251239
) : content === "profiles" ? (
252240
// profile selection

plugins/tagoio-integration/src/front/Auth/Credentials/Credentials.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type KeyboardEvent, useCallback, useRef, useState } from "react";
33
// @ts-ignore
44
import SVGTagoIO from "../../../../assets/tagoio-logo.svg";
55
import * as Style from "./Credentials.style";
6+
import { REGIONS } from "../regions.ts";
67

78
/**
89
* Props interface
@@ -17,7 +18,6 @@ interface ICredentialsProps {
1718
onLogin: () => void;
1819
selectedRegion: string;
1920
onChangeRegion: (region: "us-e1" | "eu-w1") => void;
20-
regions: Record<string, { label: string; apiUrl: string }>;
2121
}
2222

2323
/**
@@ -33,7 +33,6 @@ function Credentials(props: ICredentialsProps) {
3333
onLogin,
3434
selectedRegion,
3535
onChangeRegion,
36-
regions,
3736
} = props;
3837
const [emailError, setEmailError] = useState(false);
3938
const [passwordError, setPasswordError] = useState(false);
@@ -133,9 +132,9 @@ function Credentials(props: ICredentialsProps) {
133132
outline: "none",
134133
}}
135134
>
136-
{Object.entries(regions).map(([value, config]) => (
137-
<option key={value} value={value}>
138-
{config.label}
135+
{Object.entries(REGIONS).map(([regionKey, region]) => (
136+
<option key={regionKey} value={regionKey}>
137+
{region.label}
139138
</option>
140139
))}
141140
</select>

0 commit comments

Comments
 (0)