alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
127 lines (125 loc) • 5 kB
JavaScript
import {
useQuery
} from "../../chunks/chunk-DJKGEOOC.js";
import "../../chunks/chunk-U5RRZUYZ.js";
// src/cloud/view/CloudAuth.browser.tsx
import { Connection } from "alinea/core";
import { Client } from "alinea/core/Client";
import { joinPaths } from "alinea/core/util/Urls";
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 { data, isError } = useQuery(
["auth.cloud"],
() => {
return fetch(
joinPaths(client.options.url, Connection.routes.base, `/auth.cloud`),
{
credentials: "include"
}
).then((res) => res.json());
},
{ keepPreviousData: true }
);
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://alinea.sh/docs/deploy/exporting-the-dashboard",
target: "_blank",
children: "handler"
}
),
" ",
"to continue."
] })
] }) }) })
] });
if (!data)
return /* @__PURE__ */ jsx(Loader, { absolute: true });
const { location } = window;
switch (data.type) {
case AuthResultType.Authenticated:
setSession({
user: data.user,
cnx: client.authenticate(
(options) => ({ ...options, credentials: "same-origin" }),
() => setSession(void 0)
),
end: async () => {
location.href = joinPaths(
client.options.url,
Connection.routes.base,
`/auth/logout`
);
}
});
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://alinea.sh/docs/deploy/intro",
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
};