shellphone.app/app/core/hooks/use-require-onboarding.ts

23 lines
556 B
TypeScript
Raw Normal View History

import { Routes, useRouter } from "blitz";
2021-07-31 14:33:18 +00:00
2021-08-05 17:07:15 +00:00
import useCurrentUser from "./use-current-user";
import useCurrentPhoneNumber from "./use-current-phone-number";
2021-07-31 14:33:18 +00:00
export default function useRequireOnboarding() {
const router = useRouter();
2021-08-05 17:07:15 +00:00
const { hasFilledTwilioCredentials, hasCompletedOnboarding } = useCurrentUser();
const phoneNumber = useCurrentPhoneNumber();
2021-07-31 14:33:18 +00:00
2021-08-01 14:01:51 +00:00
if (hasCompletedOnboarding) {
return;
}
if (!hasFilledTwilioCredentials) {
throw router.push(Routes.StepTwo());
2021-07-31 14:33:18 +00:00
}
2021-08-05 17:07:15 +00:00
if (!phoneNumber) {
throw router.push(Routes.StepThree());
2021-07-31 14:33:18 +00:00
}
}