From 66dbcde29ba1a5a3e95f4e9938507a9ac1df66fa Mon Sep 17 00:00:00 2001
From: CuriousCorrelation
<58817502+CuriousCorrelation@users.noreply.github.com>
Date: Mon, 11 Jul 2022 12:29:45 +0530
Subject: [PATCH] feat: Redirect on unpublished share access (#3760)
* feat(WIP): Redirect on unpublished shares
* feat[WIP]: add redirect with test notice
* Revert to `Login` display, no redirects
---
app/scenes/Document/Shared.tsx | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/app/scenes/Document/Shared.tsx b/app/scenes/Document/Shared.tsx
index d31112641..f3439b4cf 100644
--- a/app/scenes/Document/Shared.tsx
+++ b/app/scenes/Document/Shared.tsx
@@ -4,6 +4,7 @@ import * as React from "react";
import { Helmet } from "react-helmet";
import { RouteComponentProps, useLocation } from "react-router-dom";
import { useTheme } from "styled-components";
+import { setCookie } from "tiny-cookie";
import DocumentModel from "~/models/Document";
import Error404 from "~/scenes/Error404";
import ErrorOffline from "~/scenes/ErrorOffline";
@@ -11,7 +12,8 @@ import Layout from "~/components/Layout";
import Sidebar from "~/components/Sidebar/Shared";
import useStores from "~/hooks/useStores";
import { NavigationNode } from "~/types";
-import { OfflineError } from "~/utils/errors";
+import { AuthorizationError, OfflineError } from "~/utils/errors";
+import Login from "../Login";
import Document from "./components/Document";
import Loading from "./components/Loading";
@@ -105,7 +107,14 @@ function SharedDocumentScene(props: Props) {
}, [documents, documentSlug, shareId, ui]);
if (error) {
- return error instanceof OfflineError ? : ;
+ if (error instanceof OfflineError) {
+ return ;
+ } else if (error instanceof AuthorizationError) {
+ setCookie("postLoginRedirectPath", props.location.pathname);
+ return ;
+ } else {
+ return ;
+ }
}
if (!response) {