Skip to content

Commit 9b0688b

Browse files
committed
Intercept unauthenticated guest click operations to redirect them gracefully around Next.js Server logic exceptions
1 parent 1cadbcd commit 9b0688b

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

actions/apps.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,17 @@ export async function createApp() {
6565
redirect("/builder/mock-new-id");
6666
}
6767

68-
if (!userId) throw new Error("Unauthorized");
68+
// Gracefully bounce unauthenticated 'Create New App' clicks to the sandbox
69+
if (!userId) {
70+
redirect("/builder/template-blank");
71+
}
6972

7073
const { data, error } = await supabase
7174
.from("apps")
7275
.insert({
7376
user_id: userId,
7477
name: "Untitled App",
75-
config: { app: "Untitled App", pages: [] }
78+
config: { app: "Untitled App", pages: [] },
7679
})
7780
.select("id")
7881
.single();

app/builder/[appId]/page.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,26 @@ export default function BuilderPage() {
132132
// In production without bypass, this will eventually throw `Unauthorized` and redirect them.
133133
// In development with bypass, it will mock the save successfully.
134134
setIsSaving(true);
135+
// If not signed in, mock the save locally so guests can exhaust their interaction quota cleanly
136+
if (!isSignedIn) {
137+
setTimeout(() => {
138+
setNotificationModal({
139+
type: "success",
140+
title: "Draft Saved Locally",
141+
message: "Guest changes are saved securely to your browser temporarily. Please sign in to deploy!",
142+
});
143+
setIsSaving(false);
144+
}, 500);
145+
return;
146+
}
147+
135148
try {
136149
const res = await saveAppConfig(appId, configStr);
137150
if (res && res.success === false) throw new Error(res.error);
138151
setNotificationModal({
139152
type: "success",
140153
title: "Saved Successfully",
141-
message: "Your draft has been saved securely.",
154+
message: "Your draft has been saved securely to the database.",
142155
});
143156
} catch (e: unknown) {
144157
const msg = (e as Error).message || "";

0 commit comments

Comments
 (0)