Fix api url contain undefined

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-06-13 15:59:28 -07:00
parent dfbc2aade1
commit 40f88fb812
5 changed files with 91 additions and 29 deletions

View File

@@ -2,7 +2,7 @@ import { useTranslate } from "@probo/i18n";
import { Button, Field, useToast } from "@probo/ui";
import type { FormEventHandler } from "react";
import { Link, useNavigate } from "react-router";
import { clearRelayStore } from "/providers/RelayProviders";
import { buildEndpoint, clearRelayStore } from "/providers/RelayProviders";
export default function LoginPage() {
const { __ } = useTranslate();
@@ -15,7 +15,7 @@ export default function LoginPage() {
const email = formData.get("email")?.toString();
const password = formData.get("password")?.toString();
fetch(import.meta.env.VITE_API_URL + "/api/console/v1/auth/login", {
fetch(buildEndpoint("/api/console/v1/auth/login"), {
method: "POST",
headers: {
"Content-Type": "application/json",

View File

@@ -3,6 +3,7 @@ import { Link, useNavigate } from "react-router";
import { Button, Field, useToast } from "@probo/ui";
import { useTranslate } from "@probo/i18n";
import { useMutation } from "@tanstack/react-query";
import { buildEndpoint } from "/providers/RelayProviders";
interface RegisterData {
email: string;
@@ -20,7 +21,7 @@ export default function RegisterPage() {
const registerUser = async (data: RegisterData) => {
const response = await fetch(
`${import.meta.env.VITE_API_URL}/api/console/v1/auth/register`,
buildEndpoint("/api/console/v1/auth/register"),
{
method: "POST",
headers: {
@@ -33,7 +34,10 @@ export default function RegisterPage() {
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
return { success: false, error: errorData.message || __("Registration failed") };
return {
success: false,
error: errorData.message || __("Registration failed"),
};
}
return { success: true, data: await response.json() };
@@ -103,7 +107,9 @@ export default function RegisterPage() {
type="text"
placeholder={__("John Doe")}
value={fullName}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setFullName(e.target.value)}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setFullName(e.target.value)
}
required
/>
@@ -112,7 +118,9 @@ export default function RegisterPage() {
type="email"
placeholder={__("name@example.com")}
value={email}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setEmail(e.target.value)}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setEmail(e.target.value)
}
required
/>
@@ -121,19 +129,30 @@ export default function RegisterPage() {
type="password"
placeholder="••••••••"
value={password}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setPassword(e.target.value)}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setPassword(e.target.value)
}
required
/>
<Button type="submit" className="w-full" disabled={registerMutation.isPending}>
{registerMutation.isPending ? __("Creating account...") : __("Sign up with email")}
<Button
type="submit"
className="w-full"
disabled={registerMutation.isPending}
>
{registerMutation.isPending
? __("Creating account...")
: __("Sign up with email")}
</Button>
</form>
<div className="text-center">
<p className="text-sm text-txt-tertiary">
{__("Already have an account?")}{" "}
<Link to="/login" className="underline text-txt-primary hover:text-txt-secondary">
<Link
to="/login"
className="underline text-txt-primary hover:text-txt-secondary"
>
{__("Log in here")}
</Link>
</p>