Skip to content

Commit 529169a

Browse files
committed
Cleanup
1 parent 6967ec9 commit 529169a

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

app/api/user-settings/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const schema = z.object({
66
together_api_key: z.string().min(1).max(128).optional().or(z.literal('')),
77
})
88

9+
// NOTE: This route uses SUPABASE_SERVICE_ROLE_KEY for all DB access and only accepts JWT via Authorization header. Cookies are NOT used.
10+
911
function getSupabaseAdmin() {
1012
return createClient(
1113
process.env.NEXT_PUBLIC_SUPABASE_URL!,
@@ -17,6 +19,7 @@ async function getUserFromAuthHeader(req: NextRequest) {
1719
const authHeader = req.headers.get('authorization')
1820
if (!authHeader) return null
1921
const jwt = authHeader.replace('Bearer ', '')
22+
if (!jwt) return null
2023
const supabase = getSupabaseAdmin()
2124
const { data: { user }, error } = await supabase.auth.getUser(jwt)
2225
if (error || !user) return null

app/chat/[id]/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const metadata: Metadata = {
66
description: 'Continue your conversation with AI in a modern, professional chat UI.'
77
}
88

9-
export default function ChatPage({ params }: { params: { id: string } }) {
10-
return <ClientChatPage id={params.id} />
9+
export default async function ChatPage({ params }: { params: Promise<{ id: string }> }) {
10+
const { id } = await params
11+
return <ClientChatPage id={id} />
1112
}

app/layout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const metadata: Metadata = {
3838
creator: '@yourtwitter',
3939
images: ['/og-image.png'],
4040
},
41-
themeColor: '#181a20',
4241
robots: {
4342
index: true,
4443
follow: true,
@@ -51,6 +50,10 @@ export const metadata: Metadata = {
5150
},
5251
}
5352

53+
export const viewport = {
54+
themeColor: '#181a20',
55+
}
56+
5457
// PHASE 5: Together.AI model selection and chat integration in progress
5558

5659
export default function RootLayout({

components/chat/chat-message.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,20 @@ export default function ChatMessage({ role, content, highlight, searchTerm, atta
9393
strong: (props) => <strong className="font-semibold" {...props} />,
9494
code: (props) => <code className="bg-[#f7f7fa] px-1 py-0.5 rounded text-sm text-[#23272f]" {...props} />,
9595
img: ({ src, alt }) => (
96-
<div className="my-3 flex justify-center">
97-
<img
98-
src={src || ''}
99-
alt={alt || 'generated image'}
100-
loading="lazy"
101-
className="rounded-2xl border border-[#353740] shadow-lg max-w-xs max-h-80 object-contain bg-[#23272f]"
102-
style={{ display: 'block', margin: '0 auto' }}
103-
/>
104-
</div>
96+
<img
97+
src={src || ''}
98+
alt={alt || 'generated image'}
99+
loading="lazy"
100+
className="my-3 rounded-2xl border border-[#353740] shadow-lg max-w-xs max-h-80 object-contain bg-[#23272f] block mx-auto"
101+
style={{ display: 'block', margin: '0 auto' }}
102+
/>
105103
),
106104
p: ({ children }) => {
107-
// If any child is a div (our custom img wrapper), unwrap all children
105+
// If any child is an <img>, unwrap all children to avoid <div> or <img> inside <p>
108106
if (
109107
Array.isArray(children) &&
110108
children.some(
111-
(child) => React.isValidElement(child) && child.type === 'div'
109+
(child) => React.isValidElement(child) && child.type === 'img'
112110
)
113111
) {
114112
return <>{children}</>;

components/settings/settings-modal.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,25 @@ export default function SettingsModal({ open, onClose }: SettingsModalProps) {
2222
setSuccess(null)
2323
setApiKey('')
2424
setIsLoading(true)
25-
fetch('/api/user-settings')
26-
.then(res => res.json())
27-
.then(data => {
25+
// Always get JWT and send it in the header
26+
async function fetchSettings() {
27+
try {
28+
const { data: { session } } = await supabase.auth.getSession()
29+
const jwt = session?.access_token
30+
const res = await fetch('/api/user-settings', {
31+
headers: {
32+
...(jwt ? { 'Authorization': `Bearer ${jwt}` } : {}),
33+
},
34+
})
35+
const data = await res.json()
2836
setHasKey(!!data.hasTogetherApiKey)
2937
setIsLoading(false)
30-
})
31-
.catch(() => {
38+
} catch {
3239
setError('Failed to load settings')
3340
setIsLoading(false)
34-
})
41+
}
42+
}
43+
fetchSettings()
3544
}, [open])
3645

3746
const handleSave = async (e: React.FormEvent) => {

0 commit comments

Comments
 (0)