use authenticated layout

This commit is contained in:
m5r 2021-10-24 22:25:01 +02:00
parent fbe31a508d
commit 4facb32e74
11 changed files with 20 additions and 32 deletions

View File

@ -1,6 +1,8 @@
import type { BlitzPage, GetServerSideProps } from "blitz"; import type { BlitzPage, GetServerSideProps } from "blitz";
import { getSession, Routes, useRouter } from "blitz"; import { getSession, Routes, useRouter } from "blitz";
// TODO: make this page feel more welcoming lol
const Welcome: BlitzPage = () => { const Welcome: BlitzPage = () => {
const router = useRouter(); const router = useRouter();
@ -14,8 +16,6 @@ const Welcome: BlitzPage = () => {
); );
}; };
Welcome.authenticate = { redirectTo: Routes.SignIn() };
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => { export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
const session = await getSession(req, res); const session = await getSession(req, res);
await session.$setPublicData({ shouldShowWelcomeMessage: undefined }); await session.$setPublicData({ shouldShowWelcomeMessage: undefined });

View File

@ -1,5 +1,6 @@
import type { ErrorInfo, FunctionComponent } from "react"; import type { ErrorInfo } from "react";
import { Component, Suspense } from "react"; import { Component, Suspense } from "react";
import type { BlitzLayout } from "blitz";
import { import {
Head, Head,
withRouter, withRouter,
@ -8,10 +9,11 @@ import {
CSRFTokenMismatchError, CSRFTokenMismatchError,
NotFoundError, NotFoundError,
RedirectError, RedirectError,
Routes,
} from "blitz"; } from "blitz";
import type { WithRouterProps } from "next/dist/client/with-router"; import type { WithRouterProps } from "next/dist/client/with-router";
import appLogger from "../../../../integrations/logger"; import appLogger from "integrations/logger";
import Footer from "./footer"; import Footer from "./footer";
import Loader from "./loader"; import Loader from "./loader";
@ -24,7 +26,7 @@ type Props = {
const logger = appLogger.child({ module: "Layout" }); const logger = appLogger.child({ module: "Layout" });
const AppLayout: FunctionComponent<Props> = ({ children, title, pageTitle = title, hideFooter = false }) => { const AppLayout: BlitzLayout<Props> = ({ children, title, pageTitle = title, hideFooter = false }) => {
return ( return (
<> <>
{pageTitle ? ( {pageTitle ? (
@ -49,6 +51,8 @@ const AppLayout: FunctionComponent<Props> = ({ children, title, pageTitle = titl
); );
}; };
AppLayout.authenticate = { redirectTo: Routes.SignIn() };
type ErrorBoundaryState = type ErrorBoundaryState =
| { | {
isError: false; isError: false;

View File

@ -1,6 +1,6 @@
import { Suspense, useEffect } from "react"; import { Suspense, useEffect } from "react";
import type { BlitzPage } from "blitz"; import type { BlitzPage } from "blitz";
import { Routes, dynamic } from "blitz"; import { dynamic } from "blitz";
import { atom, useAtom } from "jotai"; import { atom, useAtom } from "jotai";
import AppLayout from "app/core/layouts/layout"; import AppLayout from "app/core/layouts/layout";
@ -9,8 +9,8 @@ import NewMessageButton from "../components/new-message-button";
import MissingTwilioCredentials from "app/core/components/missing-twilio-credentials"; import MissingTwilioCredentials from "app/core/components/missing-twilio-credentials";
import useNotifications from "app/core/hooks/use-notifications"; import useNotifications from "app/core/hooks/use-notifications";
import useCurrentUser from "app/core/hooks/use-current-user"; import useCurrentUser from "app/core/hooks/use-current-user";
import PageTitle from "../../core/components/page-title"; import PageTitle from "app/core/components/page-title";
import Spinner from "../../core/components/spinner"; import Spinner from "app/core/components/spinner";
const Messages: BlitzPage = () => { const Messages: BlitzPage = () => {
const { hasFilledTwilioCredentials, hasPhoneNumber } = useCurrentUser(); const { hasFilledTwilioCredentials, hasPhoneNumber } = useCurrentUser();
@ -56,6 +56,4 @@ export const bottomSheetOpenAtom = atom(false);
Messages.getLayout = (page) => <AppLayout title="Messages">{page}</AppLayout>; Messages.getLayout = (page) => <AppLayout title="Messages">{page}</AppLayout>;
Messages.authenticate = { redirectTo: Routes.SignIn().pathname };
export default Messages; export default Messages;

View File

@ -1,6 +1,6 @@
import { Suspense } from "react"; import { Suspense } from "react";
import type { BlitzPage } from "blitz"; import type { BlitzPage } from "blitz";
import { Routes, useParam, useRouter } from "blitz"; import { useParam, useRouter } from "blitz";
import { IoChevronBack, IoInformationCircle, IoCall } from "react-icons/io5"; import { IoChevronBack, IoInformationCircle, IoCall } from "react-icons/io5";
import AppLayout from "../../../core/layouts/layout"; import AppLayout from "../../../core/layouts/layout";
@ -32,6 +32,4 @@ const ConversationPage: BlitzPage = () => {
); );
}; };
ConversationPage.authenticate = { redirectTo: Routes.SignIn() };
export default ConversationPage; export default ConversationPage;

View File

@ -1,6 +1,5 @@
import { Suspense } from "react"; import { Suspense } from "react";
import type { BlitzPage } from "blitz"; import type { BlitzPage } from "blitz";
import { Routes } from "blitz";
import AppLayout from "app/core/layouts/layout"; import AppLayout from "app/core/layouts/layout";
import MissingTwilioCredentials from "app/core/components/missing-twilio-credentials"; import MissingTwilioCredentials from "app/core/components/missing-twilio-credentials";
@ -53,6 +52,4 @@ const PhoneCalls: BlitzPage = () => {
PhoneCalls.getLayout = (page) => <AppLayout title="Calls">{page}</AppLayout>; PhoneCalls.getLayout = (page) => <AppLayout title="Calls">{page}</AppLayout>;
PhoneCalls.authenticate = { redirectTo: Routes.SignIn() };
export default PhoneCalls; export default PhoneCalls;

View File

@ -165,6 +165,4 @@ const pressBackspaceAtom = atom(null, (get, set) => {
KeypadPage.getLayout = (page) => <AppLayout title="Keypad">{page}</AppLayout>; KeypadPage.getLayout = (page) => <AppLayout title="Keypad">{page}</AppLayout>;
KeypadPage.authenticate = { redirectTo: Routes.SignIn() };
export default KeypadPage; export default KeypadPage;

View File

@ -1,5 +1,5 @@
import type { FunctionComponent } from "react";
import { Suspense } from "react"; import { Suspense } from "react";
import type { BlitzLayout } from "blitz";
import { Link, Routes, useMutation, useRouter } from "blitz"; import { Link, Routes, useMutation, useRouter } from "blitz";
import clsx from "clsx"; import clsx from "clsx";
import { import {
@ -23,7 +23,7 @@ const subNavigation = [
{ name: "Notifications", href: Routes.Notifications(), icon: IoNotificationsOutline }, { name: "Notifications", href: Routes.Notifications(), icon: IoNotificationsOutline },
]; ];
const SettingsLayout: FunctionComponent = ({ children }) => { const SettingsLayout: BlitzLayout = ({ children }) => {
const router = useRouter(); const router = useRouter();
const [logoutMutation] = useMutation(logout); const [logoutMutation] = useMutation(logout);
@ -90,4 +90,6 @@ const SettingsLayout: FunctionComponent = ({ children }) => {
); );
}; };
SettingsLayout.authenticate = { redirectTo: Routes.SignIn() };
export default SettingsLayout; export default SettingsLayout;

View File

@ -1,5 +1,6 @@
import type { BlitzPage } from "blitz"; import type { BlitzPage } from "blitz";
import { GetServerSideProps, getSession, Routes } from "blitz"; import type { GetServerSideProps } from "blitz";
import { getSession } from "blitz";
import db, { Subscription, SubscriptionStatus } from "db"; import db, { Subscription, SubscriptionStatus } from "db";
import useSubscription from "app/core/hooks/use-subscription"; import useSubscription from "app/core/hooks/use-subscription";
@ -73,8 +74,6 @@ const Billing: BlitzPage<Props> = (props) => {
Billing.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>; Billing.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>;
Billing.authenticate = { redirectTo: Routes.SignIn() };
export const getServerSideProps: GetServerSideProps<Props> = async ({ req, res }) => { export const getServerSideProps: GetServerSideProps<Props> = async ({ req, res }) => {
const session = await getSession(req, res); const session = await getSession(req, res);
const subscription = await db.subscription.findFirst({ const subscription = await db.subscription.findFirst({

View File

@ -1,5 +1,4 @@
import type { BlitzPage } from "blitz"; import type { BlitzPage } from "blitz";
import { Routes } from "blitz";
import SettingsLayout from "../../components/settings-layout"; import SettingsLayout from "../../components/settings-layout";
import ProfileInformations from "../../components/account/profile-informations"; import ProfileInformations from "../../components/account/profile-informations";
@ -20,6 +19,4 @@ const Account: BlitzPage = () => {
Account.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>; Account.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>;
Account.authenticate = { redirectTo: Routes.SignIn() };
export default Account; export default Account;

View File

@ -1,5 +1,4 @@
import type { BlitzPage } from "blitz"; import type { BlitzPage } from "blitz";
import { Routes } from "blitz";
import SettingsLayout from "../../components/settings-layout"; import SettingsLayout from "../../components/settings-layout";
@ -9,6 +8,4 @@ const Notifications: BlitzPage = () => {
Notifications.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>; Notifications.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>;
Notifications.authenticate = { redirectTo: Routes.SignIn() };
export default Notifications; export default Notifications;

View File

@ -1,5 +1,5 @@
import type { BlitzPage } from "blitz"; import type { BlitzPage } from "blitz";
import { Routes, dynamic } from "blitz"; import { dynamic } from "blitz";
import SettingsLayout from "../../components/settings-layout"; import SettingsLayout from "../../components/settings-layout";
import PhoneNumberForm from "../../components/phone/phone-number-form"; import PhoneNumberForm from "../../components/phone/phone-number-form";
@ -20,6 +20,4 @@ const TwilioApiForm = dynamic(() => import("../../components/phone/twilio-api-fo
PhoneSettings.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>; PhoneSettings.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>;
PhoneSettings.authenticate = { redirectTo: Routes.SignIn() };
export default PhoneSettings; export default PhoneSettings;