Skip to content

Commit fe988f9

Browse files
committed
navigate to api
1 parent cb8294a commit fe988f9

1 file changed

Lines changed: 38 additions & 13 deletions

File tree

src/components/Login.tsx

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { Field, Label } from "@tw/fieldset";
66
import { Heading } from "@tw/heading";
77
import { Input } from "@tw/input";
88
import { Strong, Text, TextLink } from "@tw/text";
9-
import { FormEvent, useState, useCallback, useRef, useEffect } from "react";
9+
import { FormEvent, useCallback, useEffect, useRef, useState } from "react";
1010
import { useNavigate } from "react-router";
1111
import ThemeSwitch from "./ThemeSwitch";
12+
import { RegisterUserDtoFromJSON } from "../api";
1213

1314
export function Login() {
1415
const { loginBasic, loading, error } = useAuth();
@@ -37,7 +38,7 @@ export function Login() {
3738
s = `https://${s}`;
3839
}
3940
// Remove trailing slashes
40-
s = s.replace(/\/+$/, "");
41+
s = s.replace(/\/+$/, "");
4142
return s;
4243
}, []);
4344

@@ -46,7 +47,7 @@ export function Login() {
4647
try {
4748
const normalized = normalizeServer(server);
4849
if (useSso) {
49-
// For now just disable basic login when SSO selected (future: launch popup flow)
50+
window.location.href = `${normalized}/api/auth/oauth2/login`;
5051
return;
5152
}
5253
await loginBasic({ server: normalized, username, password });
@@ -57,25 +58,35 @@ export function Login() {
5758
};
5859

5960
const handleTrapKey: React.KeyboardEventHandler = (e) => {
60-
if (e.key !== 'Tab') return;
61+
if (e.key !== "Tab") return;
6162
// Build current focusable list (skip disabled)
62-
const elems = [serverRef.current, userRef.current, passRef.current, submitRef.current]
63-
.filter((el): el is (HTMLInputElement | HTMLButtonElement) => !!el && (typeof (el as any).disabled === 'boolean' ? !(el as any).disabled : true));
63+
const elems = [
64+
serverRef.current,
65+
userRef.current,
66+
passRef.current,
67+
submitRef.current,
68+
].filter(
69+
(el): el is HTMLInputElement | HTMLButtonElement =>
70+
!!el &&
71+
(typeof (el as any).disabled === "boolean"
72+
? !(el as any).disabled
73+
: true),
74+
);
6475
if (elems.length === 0) return;
6576
const active = document.activeElement as HTMLElement | null;
66-
const currentIndex = elems.findIndex(el => el === active);
77+
const currentIndex = elems.findIndex((el) => el === active);
6778
const goingBack = e.shiftKey;
6879
if (goingBack) {
6980
// Shift+Tab on first -> go to last
7081
if (currentIndex === 0 || active == null) {
7182
e.preventDefault();
72-
elems[elems.length - 1]!.focus();
83+
elems[elems.length - 1]!.focus();
7384
}
7485
} else {
7586
// Tab on last -> go to first
7687
if (currentIndex === elems.length - 1) {
7788
e.preventDefault();
78-
elems[0]!.focus();
89+
elems[0]!.focus();
7990
}
8091
}
8192
};
@@ -89,7 +100,7 @@ export function Login() {
89100
<div tabIndex={-1} aria-hidden="true">
90101
<Logo variant="text" className="w-full" height="h-full" />
91102
</div>
92-
<Heading tabIndex={-1}>Sign in to your account</Heading>
103+
<Heading tabIndex={-1}>Sign in to your account</Heading>
93104
<Field>
94105
<Label>Server</Label>
95106
<Input
@@ -141,15 +152,29 @@ export function Login() {
141152
checked={useSso}
142153
onChange={(checked: boolean) => setUseSso(!!checked)}
143154
/>
144-
<Label htmlFor="login-sso" className="cursor-pointer">Login with SSO</Label>
155+
<Label htmlFor="login-sso" className="cursor-pointer">
156+
Login with SSO
157+
</Label>
145158
</CheckboxField>
146159
{error && (
147160
<div className="text-sm text-red-500 -mt-4" role="alert">
148161
{error}
149162
</div>
150163
)}
151-
<Button type="submit" className="w-full" disabled={loading} tabIndex={4} ref={submitRef}>
152-
{loading ? (useSso ? 'Preparing SSO…' : 'Authenticating…') : (useSso ? 'Continue with SSO' : 'Login')}
164+
<Button
165+
type="submit"
166+
className="w-full"
167+
disabled={loading}
168+
tabIndex={4}
169+
ref={submitRef}
170+
>
171+
{loading
172+
? useSso
173+
? "Preparing SSO…"
174+
: "Authenticating…"
175+
: useSso
176+
? "Continue with SSO"
177+
: "Login"}
153178
</Button>
154179
<Text tabIndex={-1} aria-hidden="true">
155180
Don’t have an account? {""}

0 commit comments

Comments
 (0)