File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change 1515 import { onMount , tick } from " svelte" ;
1616 import { loading } from " $lib/stores/loading.js" ;
1717 import { loadAttachmentsFromUrls } from " $lib/utils/loadAttachmentsFromUrls" ;
18+ import { requireAuthUser } from " $lib/utils/auth" ;
1819
1920 let { data } = $props ();
2021
5253 });
5354
5455 if (! res .ok ) {
55- const errorMessage = (await res .json ()).message || ERROR_MESSAGES .default ;
56+ let errorMessage = ERROR_MESSAGES .default ;
57+ try {
58+ const json = await res .json ();
59+ errorMessage = json .message || errorMessage ;
60+ } catch {
61+ // Response wasn't JSON (e.g., HTML error page)
62+ if (res .status === 401 ) {
63+ errorMessage = " Authentication required" ;
64+ }
65+ }
5666 error .set (errorMessage );
5767 console .error (" Error while creating conversation: " , errorMessage );
5868 return ;
7888
7989 onMount (async () => {
8090 try {
91+ // Check if auth is required before processing any query params
92+ const hasQ = page .url .searchParams .has (" q" );
93+ const hasPrompt = page .url .searchParams .has (" prompt" );
94+ const hasAttachments = page .url .searchParams .has (" attachments" );
95+
96+ if ((hasQ || hasPrompt || hasAttachments ) && requireAuthUser ()) {
97+ return ; // Redirecting to login, will return to this URL after
98+ }
99+
81100 // Handle attachments parameter first
82- if (page . url . searchParams . has ( " attachments " ) ) {
101+ if (hasAttachments ) {
83102 const result = await loadAttachmentsFromUrls (page .url .searchParams );
84103 files = result .files ;
85104
Original file line number Diff line number Diff line change 1212 import { pendingMessage } from " $lib/stores/pendingMessage" ;
1313 import { sanitizeUrlParam } from " $lib/utils/urlParams" ;
1414 import { loadAttachmentsFromUrls } from " $lib/utils/loadAttachmentsFromUrls" ;
15+ import { requireAuthUser } from " $lib/utils/auth" ;
1516
1617 let { data } = $props ();
1718
6465
6566 onMount (async () => {
6667 try {
68+ // Check if auth is required before processing any query params
69+ const hasQ = page .url .searchParams .has (" q" );
70+ const hasPrompt = page .url .searchParams .has (" prompt" );
71+ const hasAttachments = page .url .searchParams .has (" attachments" );
72+
73+ if ((hasQ || hasPrompt || hasAttachments ) && requireAuthUser ()) {
74+ return ; // Redirecting to login, will return to this URL after
75+ }
76+
6777 // Handle attachments parameter first
68- if (page . url . searchParams . has ( " attachments " ) ) {
78+ if (hasAttachments ) {
6979 const result = await loadAttachmentsFromUrls (page .url .searchParams );
7080 files = result .files ;
7181
You can’t perform that action at this time.
0 commit comments