[CHORE] Implement RedirectURIs
Some checks failed
S3 Repo Backup / s3-repo-backup (push) Failing after 1s
Deploy Edge / deploy-edge (push) Failing after 8s

This commit is contained in:
Dunemask 2024-08-24 16:51:30 -06:00
parent 0fc5f05b6a
commit fdb19be2ef
12 changed files with 91 additions and 33 deletions

View file

@ -4,24 +4,28 @@ import { Resource } from "@lib/vix/AppResources";
import { SyntheticEvent, useState } from "react";
import { toast } from "react-toastify";
import { useAuth } from "@src/ctx/AuthContext";
import { useAutoRedirect } from "@src/util/links";
import { Links, rootLink, useAutoRedirect } from "@src/util/links";
import { ClientError } from "@dunemask/vix/bridge";
import { AuthErrors } from "@lib/vix/ClientErrors";
import { PasswordInput } from "@src/components/common/Inputs";
import { ResourcePolicyType } from "@dunemask/vix/util";
import { postProjectAuthLogin } from "@src/util/api/GeneratedRequests";
import { Navigate, useSearchParams } from "react-router-dom";
const project = import.meta.env.VITE_CAIRO_PROJECT as string;
export default function AuthenticateView() {
const { auth, login } = useAuth();
const autoRedirect = useAutoRedirect();
const [search] = useSearchParams();
const [identity, setIdentity] = useState<string>("");
const [password, setPassword] = useState<string>("");
const projectId = search.get("projectId") ?? project;
const identityChange = (e: SyntheticEvent) => setIdentity((e.target as HTMLInputElement).value);
function submitCredentials() {
const loginPromise = postProjectAuthLogin(project, { identity: identity, password }).then(async (creds) => {
const loginPromise = postProjectAuthLogin(projectId, { identity: identity, password }).then(async (creds) => {
if (!creds.token) return toast.error("Server didn't provide token!");
await login(
creds.user,
@ -48,7 +52,7 @@ export default function AuthenticateView() {
function detectEnter(e: KeyboardEvent) {
if (e.key === "Enter") submitCredentials();
}
if (auth) return;
if (auth) return <Navigate to={rootLink(Links.AutoRedirect)} />;
return (
<Box width="100%" height="90vh" display="flex" alignItems="center" justifyContent="center">
<Box p="2rem" width="100%" maxWidth="350px" boxShadow="md" borderRadius="md" bg="background.paper">