Skip to content

Commit 29addb5

Browse files
committed
feat: Acknowledge unauthorized notes access and redirect
1 parent fdbe179 commit 29addb5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/app/note/[id]/novelEditor.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { Editor } from "novel";
2121
import { useEffect, useState } from "react";
2222
import { type JSONContent } from "@tiptap/core";
2323
import crypto from "crypto";
24+
import { toast } from "@/components/ui/use-toast";
25+
import { redirect } from "next/navigation";
2426
// import {placeholder} from './defaultData';
2527

2628
function NovelEditor({ id }: { id: string }) {
@@ -36,7 +38,17 @@ function NovelEditor({ id }: { id: string }) {
3638
try {
3739
const response = await fetch(`/api/note?id=${id}`);
3840

39-
if (response.status === 404) {
41+
if (response.status === 401) {
42+
toast({
43+
title: "You don't have permissions not view/edit this note!",
44+
description: "Redirecting to dashboard in 8 seconds",
45+
variant: "destructive",
46+
});
47+
setTimeout(() => {
48+
window.location.href = '/dash'; // Redirect after 10 seconds
49+
}, 8_000);
50+
return null;
51+
} else if (response.status === 404) {
4052
return null;
4153
} else if (!response.ok) {
4254
throw new Error("Network response was not ok");
@@ -91,7 +103,10 @@ function NovelEditor({ id }: { id: string }) {
91103
return (
92104
<>
93105
{syncWithCloudWarning && (
94-
<Warning handleKeepLocalStorage={handleKeepLocalStorage} handleKeepCloudStorage={handleKeepCloudStorage} />
106+
<Warning
107+
handleKeepLocalStorage={handleKeepLocalStorage}
108+
handleKeepCloudStorage={handleKeepCloudStorage}
109+
/>
95110
)}
96111
<div className="relative w-full max-w-screen-lg pb-8">
97112
<div className="absolute right-5 top-5 mb-5 rounded-lg bg-stone-100 px-2 py-1 text-sm text-stone-400">

0 commit comments

Comments
 (0)