Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions packages/client/components/auth/src/flows/FlowCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Trans } from "@lingui-solid/solid/macro";

import { useApi, useClient } from "@revolt/client";
import { useApi, useClient, useClientLifecycle } from "@revolt/client";
import { CONFIGURATION } from "@revolt/common";
import { useNavigate, useParams } from "@revolt/routing";
import { Button, Row, iconSize } from "@revolt/ui";
import { useModals } from "@revolt/modal";

import MdArrowBack from "@material-design-icons/svg/filled/arrow_back.svg?component-solid";

Expand All @@ -20,6 +21,8 @@ export default function FlowCreate() {
const getClient = useClient();
const navigate = useNavigate();
const { code } = useParams();
const { login } = useClientLifecycle();
const modals = useModals();

/**
* Create an account
Expand All @@ -38,15 +41,31 @@ export default function FlowCreate() {
...(invite ? { invite } : {}),
});

// FIXME: should tell client if email was sent
// or if email even needs to be confirmed
if (needsEmailVerification()) {
redirectToEmailVerification(email);
} else {
await loginDirectly(email, password);
}
}

// TODO: log straight in if no email confirmation?
function needsEmailVerification() {
const client = getClient();
if (client.configured()) {
return client.configuration?.features.email;
}
return true;
}

function redirectToEmailVerification(email: string) {
setFlowCheckEmail(email);
navigate("/login/check", { replace: true });
}

async function loginDirectly(email: string, password: string) {
await login({ email, password }, modals);
navigate("/login/auth", { replace: true });
}

const isInviteOnly = () => {
const client = getClient();
if (client.configured()) {
Expand Down