alinea
Version:
Headless git-based CMS
112 lines (110 loc) • 4.67 kB
JavaScript
import {
useQuery
} from "../../chunks/chunk-YWCPLD22.js";
import "../../chunks/chunk-NZLE2WMY.js";
// src/cloud/view/CloudAuth.browser.tsx
import { Client } from "alinea/core/Client";
import { useDashboard } from "alinea/dashboard/hook/UseDashboard";
import { Head } from "alinea/dashboard/util/Head";
import { Button, HStack, px, Typo, VStack } from "alinea/ui";
import { LogoShape } from "alinea/ui/branding/LogoShape";
import { IcRoundArrowForward } from "alinea/ui/icons/IcRoundArrowForward";
import { IcRoundPublish } from "alinea/ui/icons/IcRoundPublish";
import { Loader } from "alinea/ui/Loader";
import { AuthResultType } from "../AuthResult.js";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
function CloudAuthView({ setSession }) {
const { client } = useDashboard();
if (!(client instanceof Client))
throw new Error("Cannot authenticate with non http client");
const clientUrl = new URL(client.url, window.location.href);
const { data, isError } = useQuery(["auth.status"], () => client.authStatus(), {
cacheTime: 0,
keepPreviousData: false
});
if (isError)
return /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(Head, { children: /* @__PURE__ */ jsx("title", { children: "Alinea" }) }),
/* @__PURE__ */ jsx("div", { style: { display: "flex", height: "100%", width: "100%" }, children: /* @__PURE__ */ jsx("div", { style: { margin: "auto", padding: px(20) }, children: /* @__PURE__ */ jsxs(VStack, { gap: 20, children: [
/* @__PURE__ */ jsxs(HStack, { center: true, gap: 16, children: [
/* @__PURE__ */ jsx(LogoShape, { children: /* @__PURE__ */ jsx(IcRoundPublish, {}) }),
/* @__PURE__ */ jsx(Typo.H1, { flat: true, children: "Ready to deploy?" })
] }),
/* @__PURE__ */ jsxs(Typo.P, { children: [
"Alinea requires a",
" ",
/* @__PURE__ */ jsx(
Typo.Link,
{
href: "https://alineacms.com/docs/deploy",
target: "_blank",
children: "handler"
}
),
" ",
"to continue."
] })
] }) }) })
] });
if (!data) return /* @__PURE__ */ jsx(Loader, { absolute: true });
const { location } = window;
switch (data.type) {
case AuthResultType.NeedsRefresh:
throw new Error("Authentication failure, please refresh the page");
case AuthResultType.Authenticated:
setSession({
user: data.user,
cnx: client.authenticate(
(options) => options,
() => setSession(void 0)
)
});
return null;
case AuthResultType.UnAuthenticated:
location.href = `${data.redirect}&from=${encodeURIComponent(
`${location.protocol}//${location.host}${location.pathname}`
)}`;
return null;
case AuthResultType.MissingApiKey:
return /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(Head, { children: /* @__PURE__ */ jsx("title", { children: "Alinea" }) }),
/* @__PURE__ */ jsx("div", { style: { display: "flex", height: "100%", width: "100%" }, children: /* @__PURE__ */ jsx("div", { style: { margin: "auto", padding: px(20) }, children: /* @__PURE__ */ jsxs(VStack, { gap: 20, children: [
/* @__PURE__ */ jsxs(HStack, { center: true, gap: 16, children: [
/* @__PURE__ */ jsx(LogoShape, { children: /* @__PURE__ */ jsx(IcRoundPublish, {}) }),
/* @__PURE__ */ jsx(Typo.H1, { flat: true, children: "Ready to deploy?" })
] }),
/* @__PURE__ */ jsxs(Typo.P, { children: [
"Alinea requires a backend to continue.",
/* @__PURE__ */ jsx("br", {}),
"You can",
" ",
/* @__PURE__ */ jsx(
Typo.Link,
{
href: "https://alineacms.com/docs/deploy",
target: "_blank",
children: /* @__PURE__ */ jsx("span", { children: "fully configure a custom backend" })
}
),
".",
/* @__PURE__ */ jsx("br", {}),
"Or get set up in a few clicks with our cloud offering."
] }),
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
Button,
{
as: "a",
href: `${data.setupUrl}?from=${encodeURIComponent(
`${location.protocol}//${location.host}${location.pathname}`
)}`,
iconRight: IcRoundArrowForward,
children: "Continue with alinea.cloud"
}
) })
] }) }) })
] });
}
}
export {
CloudAuthView
};