This commit is contained in:
2025-04-13 19:18:07 +01:00
parent 5ae6a3403f
commit eba4268718
2 changed files with 23 additions and 16 deletions

View File

@ -1,7 +1,7 @@
import { Button } from "@kobalte/core/button";
import { TextField } from "@kobalte/core/text-field";
import { createSignal, Show, type Component } from "solid-js";
import { postCode, postLogin } from "./network";
import { base, postCode, postLogin } from "./network";
import { isTokenValid } from "./ProtectedRoute";
import { Navigate } from "@solidjs/router";
@ -40,20 +40,23 @@ export const Login: Component = () => {
const isAuthorized = isTokenValid();
return (
<Show when={!isAuthorized} fallback={<Navigate href="/" />}>
<form ref={form} onSubmit={onSubmit}>
<TextField name="email">
<TextField.Label>Email</TextField.Label>
<TextField.Input />
</TextField>
<Show when={submitted()}>
<TextField name="code">
<TextField.Label>Code</TextField.Label>
<>
{base}
<Show when={!isAuthorized} fallback={<Navigate href="/" />}>
<form ref={form} onSubmit={onSubmit}>
<TextField name="email">
<TextField.Label>Email</TextField.Label>
<TextField.Input />
</TextField>
</Show>
<Button type="submit">Submit</Button>
</form>
</Show>
<Show when={submitted()}>
<TextField name="code">
<TextField.Label>Code</TextField.Label>
<TextField.Input />
</TextField>
</Show>
<Button type="submit">Submit</Button>
</form>
</Show>
</>
);
};

View File

@ -17,8 +17,12 @@ type BaseRequestParams = Partial<{
method: "GET" | "POST";
}>;
export const base = import.meta.env.DEV
? "http://localhost:3040"
: "https://haystack.johncosta.tech";
const getBaseRequest = ({ path, body, method }: BaseRequestParams): Request => {
return new Request(`http://localhost:3040/${path}`, {
return new Request(`${base}/${path}`, {
body,
method,
});
@ -29,7 +33,7 @@ const getBaseAuthorizedRequest = ({
body,
method,
}: BaseRequestParams): Request => {
return new Request(`http://localhost:3040/${path}`, {
return new Request(`${base}/${path}`, {
headers: {
Authorization: `Bearer ${localStorage.getItem("access")?.toString()}`,
},